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

Mongoose __v when does it change

According to http://aaronheckmann.tumblr.com/post/48943525537/mongoose-v3-part-1-versioning The version field __v is suppose to change when array elements are shifted out of their original position. I run a test code (Mongoose version 3.8.15): var…
huggie
  • 17,587
  • 27
  • 82
  • 139
8
votes
1 answer

MongoDB / Mongoose Schema for Threaded Messages (Efficiently)

I'm somewhat new to noSQL databases (I'm fairly good with relational databases though), and I'm wondering what the most efficient way to handle an inbox system with threaded messages would be. Each 'message' will have a single sender and recipient. …
High Owl
  • 103
  • 1
  • 7
8
votes
1 answer

Mongoose error: Cannot update __v and __v at the same time

I need help with this. I have this node project that's been working from the beginning. Recently I began getting an error about mongoose not being able to update __v an __v at the same time (details below) My first thought was that a new update of…
user3863128
  • 81
  • 1
  • 4
8
votes
2 answers

Undefined model fields with `strict: false`

var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/test', {user: 'mongod'}); mongoose.connection.once('open', function () { I create a model with one field and strict: false var Foo = mongoose.model('Foo',…
Karolis Juodelė
  • 3,708
  • 1
  • 19
  • 32
8
votes
2 answers

Mongodb set _id as decreasing index

I want to use mongodb's default _id but in decreasing order. I want to store posts and want to get the latest posts at the start when I use find(). I am using mongoose. I tried with postSchema.index({_id:-1}) but it didn't work >…
ma08
  • 3,654
  • 3
  • 23
  • 36
8
votes
2 answers

MongoDB slow initial connection

I am facing a really weird scenario, the initial connection to mongoDb takes around 15 seconds. My current setup is the following: mongodb running inside an ubuntu vm on the same machine mongodb is version 2.6.1 node.js installed using brew and it…
Fouad
  • 855
  • 1
  • 11
  • 30
8
votes
4 answers

JavaScript Promises mongoose and bluebird missing catch and fail

I've started using promises, I use Node.js Mango (with mongoose) and bluebird.. The issue I'm having is for some reason when I chain the mongoose call with functions returning promises (I'm assuming this is the correct way to return and chain) then…
Dory Zidon
  • 10,497
  • 2
  • 25
  • 39
8
votes
3 answers

MongooseJS cant disable unique to field

This is my mongoosejs schema. I set name unique to false, but this is what i get: MongoError: insertDocument :: caused by :: 11000 E11000 duplicate key error index: testdb1.images.$name_1 dup key: { : "aaa" } imageSchema = new Schema({ url: { …
nobody_cares_
  • 139
  • 2
  • 9
8
votes
0 answers

Mongoose Populate() like functionality in C# Mongo Driver

Using Mongoose, we can populate reference document My Document look like this, var Menu = new Schema({ name: String, items:[{ type: ObjectId, ref: 'Items' }], I have stored item document _id in Menu.Items. So whenever i want to menu with items…
Hiren S.
  • 2,793
  • 15
  • 25
8
votes
1 answer

How to pull all elements from array in MongoDB without any condition

I have a document as below, and I want to pull all the elements in this array without any condition just via one statement. how can I do? "energy_sent" : [ { "player_id" : "034010000093", "_id" :…
Hunter Zhao
  • 4,589
  • 2
  • 25
  • 39
8
votes
2 answers

What are all of the possible callback params for mongoose Document#update?

This seems really poorly documented.. The documentation example just has callback being passed to update. There is a link redirecting to Model.update here and the example shows the parameters of the callback are (err, numberAffected, raw). Does the…
JuJoDi
  • 14,627
  • 23
  • 80
  • 126
8
votes
2 answers

Mongoose Query: Find an element inside an array

Mongoose/Mongo noob here: My Data Here is my simplified data, each user has his own document { "__v" : 1, "_id" : ObjectId( "53440e94c02b3cae81eb0065" ), "email" : "test@test.com", "firstName" : "testFirstName", "inventories" : [ {…
NicolasMoise
  • 7,261
  • 10
  • 44
  • 65
8
votes
1 answer

How do I unit test keystonejs models?

Is there any way to run tests for keystonejs that also hit a test or real mongodb instance? It would be nice if similar to the way Django does it.
endre
  • 1,363
  • 1
  • 11
  • 22
8
votes
4 answers

Mongoose returns undefined for an existing field

After a mongoose request I have my document doc which is the result of the query Here is the schema used var searchSchema = new mongoose.Schema({ original : String, images : [String], image: String }); The model : var searchModel =…
nialna2
  • 2,056
  • 2
  • 25
  • 33
8
votes
2 answers

Node mongoose find query in loop not working

I am trying to fetch records from mongoose in loop. But it is not working as expected. I have an array of hashes with questions and answers and I'm trying to find those questions from my db. Here is my loop: for (var i=0;i < answers.length;i++) { …
nOmi
  • 297
  • 3
  • 22