I recently created a web application utilizing MongoDB databases hosted on Atlas, connected through Stitch. However, I discovered that Stitch has been deprecated and replaced by MongoDB Realm. So, I decided to update my site to use Realm instead of Stitch. Interestingly, after the update, I noticed that anonymous log-ins were significantly slower for some reason. To investigate this, I conducted some quick tests following the code provided in MongoDB's documentation:
let t0 = performance.now()
app.logIn(Realm.Credentials.anonymous()).then(() => {
let t1 = performance.now()
db.collection('test').find({
category: "test"
}, {limit: 10})
console.log("Login took " + (t1 - t0) + " milliseconds.")
})
It now takes an astonishing 1200 ms
to log in.
let t0 = performance.now()
app.auth.loginWithCredential(new stitch.AnonymousCredential()).then(() => {
let t1 = performance.now()
db.collection('test').find({
category: 'test'
}, {limit: 10}).asArray()
console.log("Login took " + (t1 - t0) + " milliseconds.")
})
In comparison, with Stitch, it usually only takes under 20 ms
to log in.
Any insights into why there is such a difference or suggestions on how to resolve this issue? I am aware of the option to first authenticate a user as outlined in their documentation, but even trying that method resulted in slow log-ins.
Is it necessary to transition to the new Realm App, considering that the old Stitch implementation may stop functioning in the near future? Any information on this matter would be greatly appreciated ;)
Update: Further investigation revealed that the slower performance with Realm is due to the fact that logging in using
logIn(Realm.Credentials.anonymous()).then(() => ...
triggers two Post requests, while auth.loginWithCredential(new stitch.AnonymousCredential()).then(() => ...
combines authentication and content download into a single request. This results in a TTFB waiting time of 500-700 ms twice with Realm, compared to just once with Stitch.