I would like to create a sort of a ‘dashboard’ on a capped collection (which is used as a log table) on my Mongo database. This is how I create the collection: I do a collection.find(), with options tailable:true, awaitdata:true, and numberOfRetries:-1 (infinite retries). What puzzles me is that I’d expect the find().each() loop to wait for new data (messages)…
Tag: mongodb
node.js mongodb .. the (immutable) field ‘_id’ was found to have been altered
I have some problem when I try to upsert my object with new ones(parsed from xml file),but I got the following error: Here is my code: I tried to use hints like: but they didn’t help. So I don’t want to update my product._id , I just want to update the other fields. Answer When you do new Product(), a
How to query a field in MongoDB with a boolean value and return a boolean whether it’s true or false
Check my simple collection: What I want to do once a document is found, is to manipulate a DOM and show a <div class=”driving-tutorial> if the field canDrive value is false and hide it if the value is true Like this in meteor: Answer You could implement this logic with the findOne() method which finds the first document that matches
SyntaxError: Unexpected token
I am using MongoDB + Node.js to create an app, but I am receiving an error for this code: company.js api.js Error friends.name: req.body.friendName, SyntaxError: Unexpected token . I also tried with friend[‘name’] but the result was the same: SyntaxError: Unexpected token [ Please tell me where is my mistake Answer Try: or: depend on what you’re after.
Mongoose JS findOne always returns null
I’ve been fighting with trying to get Mongoose to return data from my local MongoDB instance; I can run the same command in the MongoDB shell and I get results back. I have found a post on stackoverflow that talks about the exact problem I’m having here; I’ve followed the answers on this post but I still can’t seem to
Shorten ObjectId in node.js and mongoose
my URLs look like this at the moment: So, as you can see, it gets pretty long, pretty fast. I was thinking about shortening these ObjectIds. Idea is that I should add new field called “shortId” to every model in my database. So instead of having: we would have this: I found a way to do it like this: But
Mongoose auto increment
According to this mongodb article it is possible to auto increment a field and I would like the use the counters collection way. The problem with that example is that I don’t have thousands of people typing the data in the database using the mongo console. Instead I am trying to use mongoose. So my schema looks something like this:
Return certain fields with .populate() from Mongoose
I’m getting returned a JSON value from MongoDB after I run my query. The problem is I do not want to return all the JSON associated with my return, I tried searching the docs and didn’t find a proper way to do this. I was wondering what if it is at possible, and if so what is the proper way
Find documents with array that doesn’t contains a specific value
I have the following model: I am looking for a query that retrieves all the Persons that are not part of a certain Group (i.e the persons’ group array doesn’t contain the id of the specified group). I was thinking about something like this, but I’m not sure it is correct: Person.find({groups: {$nin: [group._id]}) Answer Nothing wrong with what you
Mongoose find/update subdocument
I have the following schemas for the document Folder: So, for each Page I can have many permissions. In my CMS there’s a panel where I list all the folders and their permissions. The admin can edit a single permission and save it. I could easily save the whole Folder document with its permissions array, where only one permission was