Questions tagged [mongoose]

Mongoose is a MongoDB object modeling tool, or ODM (Object Document Mapper), written in JavaScript and designed to work in an asynchronous environment.

Mongoose is a MongoDB object modeling tool, or ODM (Object Document Mapper), written in JavaScript and designed to work in an asynchronous environment.

Documentation

Related links

To open a bug or feature request, visit: https://github.com/Automattic/mongoose/issues

For Mongoose, an embeddable web server written in C, use .

Installations

npm install --save mongoose
46587 questions
8
votes
1 answer

mongodb coalesce equivalent (with mongoose)

I have a localization collection where each document is a key-value pair translated into multiple languages. This is a JSON representation: [ { "_id": "form.password" , "en": "Password" , "he": "סיסמא" , "ru": "пароль" } { "_id": "form.email"…
Ilan Frumer
  • 32,059
  • 8
  • 70
  • 84
8
votes
2 answers

Mongoose save() method not writing to database

So I'm updating an attribute of a user sub document in mongoose, but it's not saving to my database. Here's my function: @User.findOne({'email': email}, (err, user) -> if err? callback(err) else if user? for account in…
Connor Black
  • 6,921
  • 12
  • 39
  • 70
8
votes
4 answers

Is there a way to use a variable for the field name in a find() in mongoose?

Say you have a very long generic function you want to use over multiple schemas, and each schema has a different name for the field you're querying (and possibly different type of value -- string, number, etc.) function foo (field, value){ …
PGT
  • 1,468
  • 20
  • 34
8
votes
2 answers

Mongoose - Anyway to prevent middleware save hooks from executing under certain conditions (e.g. being saved as subdocument)?

I have a schema Foo which has pre and post save hooks. For a special debugging application I'm writing, I grab all the active Foo objects. Then, save them as a subdocument as part of a History schema. When I save it as part of the subdocument, I do…
blak3r
  • 16,066
  • 16
  • 78
  • 98
8
votes
1 answer

Is Mongoose save async?

New to mongoose & node. I can't figure out if mongoose document.save method is async. I'm assuming that it is, since it works even when not connected. Is there a way to tell when the document is actually saved (callback)?
hba
  • 7,406
  • 10
  • 63
  • 105
8
votes
4 answers

mongoose objectid to number

How can I cast an ObjectId to a number? In my app I'm using the latest mongoose version and backbone on the clientside. My problem is that the ObjectId always ends up being put in between quotes which results in double quotes like ""233453452534""…
user832035
8
votes
1 answer

Mongoose: doesn't put _id to embedded document

var Embedded = new Schema({ some: String }) var Main = new Schema({ other: String, em: [Embedded] }) On Main.save({other:1, em:[{some:2}]}) mongoose adds object {other:1, em:[{some:2,"_id" : ObjectId("51f6d89a6269170000000039")}]} to the…
adsurbum
  • 3,107
  • 3
  • 22
  • 27
8
votes
2 answers

Update a record where _id = :id with Mongoose

I'm trying to update an existing record with Mongoose. The insert is OK but not the update. Here is my snippet: app.post('/submit', function(req, res) { var my_visit = new models.visits({ date: req.body.visit_date, type:…
Syl
  • 2,232
  • 8
  • 34
  • 45
8
votes
1 answer

Mongoose find last ten entries in database

I am making a simple little Social Network. I have all the inputting posts, users, etc, done. The only thing wrong right now is it is pretty much just a chat room. Whenever you post something on someone's page, the only people that can view it…
Beaurocks16
  • 341
  • 1
  • 7
  • 16
8
votes
3 answers

Use mongoose query to get only a subdocument

I have a similar datastructure as this: var GrandGrandChild = mongoose.Schema({ attribute: String, id: Number }); var GrandChild = mongoose.Schema({ children: [GrandGrandChild], id: Number, irrelevantAttribute: String }); var…
Hylke
  • 598
  • 1
  • 3
  • 17
8
votes
3 answers

How can I prevent the browser's back button from accessing restricted information, after the user has logged out?

I'm Using this example found on github for passport local strategy with mongoose/mongodb. The problem that I'm encountering is that when a user logs out, they can still access restricted information by hitting the back button on the browser. I'm…
Scott
  • 1,322
  • 4
  • 23
  • 37
8
votes
1 answer

MongoDB: select matched elements of subcollection

I'm using mongoose.js to do queries to mongodb, but I think my problem is not specific to mongoose.js. Say I have only one record in the collection: var album = new Album({ tracks: [{ title: 'track0', language: 'en', },{ …
WHITECOLOR
  • 24,996
  • 37
  • 121
  • 181
8
votes
5 answers

Ember, Ember Data and MongoDB's _id

I've seen this question talked about but I'm still having issues with manhandling Mongo's _id into id. I'm using mongoose as my ORM and while it has virtuals I can't seem to get it to work properly. Below is what I have in my mongoose…
Chad
  • 18,076
  • 8
  • 31
  • 41
8
votes
1 answer

Finding a MongoDB document by ObjectId with Mongoose

I am trying to update a document in MongoDB by finding it by the ObjectId. The work flow is as follows (this is for a blog). Create a new post in MongoDB by passing a title and body. The ObjectId is automatically created. Go to edit the post. It…
David Yeiser
  • 1,438
  • 5
  • 22
  • 33
8
votes
2 answers

Mongoose 3.4.0 returns [object Object] instead of actual values - Nodejs

This is my schema var elementSchema = new Schema({ name: String, storage: { url: String, type: String } }); However when I: var newElement = new Element(); newElement.storage = {}; newElement.storage.url = "asd"; …
piggyback
  • 9,034
  • 13
  • 51
  • 80