I am trying to insert a "question" document into the DB, and then redirect to a page to display the newly inserted question. The doc does get inserted, but the redirect happens to the pre-existing question instead. The problem seems to be that the highest index is not available on the client side. Is this because "friendlySlugs" is not being published to the client side?
friendlySlugs DEBUG: = before.insert function
todda00_friendly-slugs.js:325 friendlySlugs DEBUG: = Begin runSlug
todda00_friendly-slugs.js:322 friendlySlugs DEBUG: Options↓
todda00_friendly-slugs.js:323 ObjectcreateOnUpdate: truedebug: truedistinct: truedistinctUpTo: Array[0]maxLength: 0slugField: "slug"slugFrom: "questionText"transliteration: Array[31]updateSlug: true__proto__: Object
todda00_friendly-slugs.js:325 friendlySlugs DEBUG: Modifier= false
todda00_friendly-slugs.js:325 friendlySlugs DEBUG: Create= false
todda00_friendly-slugs.js:325 friendlySlugs DEBUG: Slugging From= q2
todda00_friendly-slugs.js:325 friendlySlugs DEBUG: SlugBase before reduction= q2
todda00_friendly-slugs.js:325 friendlySlugs DEBUG: SlugBase after reduction= q2
todda00_friendly-slugs.js:325 friendlySlugs DEBUG: Highest indexed base found= undefined
todda00_friendly-slugs.js:325 friendlySlugs DEBUG: finalSlug= q2
todda00_friendly-slugs.js:325 friendlySlugs DEBUG: = Set to update
todda00_friendly-slugs.js:322 friendlySlugs DEBUG: Final Doc↓
todda00_friendly-slugs.js:323 Object
methods.js:26 New Question ID: h3i3pQvYqguF4Z5Et
methods.js:29 Going to: /question/q2
Observations:
Those last 2 lines in both the logs are created by the same console.log statements in my methods.js. As you can see, it does insert the document, but sends it to the wrong URL.
Highest indexed base found for server is the right object, but the same for the client is undefined. I believe this is the root of the problem.
This is happening because the client side is not subscribed to all the data, so it thinks q2 is the correct slug. The best way to handle this situation is to do one of the following:
Complete your insert and slug lookup commands in a server only method, which has access to all data and will use the correct slug.
create a server method to receive an _id and return the slug, then call this on the client before routing.
I am trying to insert a "question" document into the DB, and then redirect to a page to display the newly inserted question. The doc does get inserted, but the redirect happens to the pre-existing question instead. The problem seems to be that the highest index is not available on the client side. Is this because "friendlySlugs" is not being published to the client side?
On the server, I get:
And on the client, I get:
Observations:
console.log
statements in my methods.js. As you can see, it does insert the document, but sends it to the wrong URL.Highest indexed base found
for server is the right object, but the same for the client isundefined
. I believe this is the root of the problem.My code in methods.js:
In collections.js: