Giter Site home page Giter Site logo

mockgoose's People

Contributors

akaashanky avatar alexandrusavin avatar atstp avatar chornyi avatar feleir avatar fodor0205 avatar fracmak avatar francesko avatar godu avatar hgcummings avatar jbach avatar krisb avatar lslah avatar mccormicka avatar mctep avatar nepoxx avatar nukulb avatar ovatto avatar pibi avatar rysenko avatar seansullivan avatar simenb avatar twistedstream avatar vdeturckheim avatar wavded avatar winfinit avatar yads avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mockgoose's Issues

Schema gets mutated?

I am having a hard time figuring out mockgoose. Everything works fine in development, but then when switching to mockgoose a lot of things are not saved, or saved in the wrong location:

contract.titles[0].runs =6; contract.save();
result returned from save is fine:   "titles":[{"runs":6,"....
but on next lookup it is wrong: "titles.0.runs":6 

instead of being in the titles[] array, it is now its own new property??

Disable logging

It would be nice to disable logging (I saw a mention of piping using bunyan but that won't work inside my test runner), or perhaps set the logging for bunyan.

Thoughts?

Nested array values or references cannot be queried

Here is my failing test for this one. Looks like it does what you'd expect until its nested:

var mockgoose = require('mockgoose')
var mongoose = require('mongoose')
mockgoose(mongoose)
var assert = require('assert')

var ObjectId = mongoose.Schema.Types.ObjectId

var schema = new mongoose.Schema({
  values: [String],
  nestedValues: [{ value: String}],
  refs: [{ type: ObjectId, ref: 'Ref' }],
  nestedRefs: [{ _ref: { type: ObjectId, ref: 'Ref' } }]
})
var rschema = new mongoose.Schema()

var Test = mongoose.model('Test', schema)
var Ref = mongoose.model('Ref', rschema)

var refA = new Ref()
var refB = new Ref()

Test.create({
  values: ['Foo','Bar','Baz'],
  nestedValues: [{ value: 'Bob' }, { value: 'Bill' }, { value: 'Jim' }],
  refs: [ refA, refB ],
  nestedRefs: [{ _ref: refA }, { _ref: refB }]
}, function (er, test) {
  Test.count({ values: 'Baz' } , function (er, count) {
    assert.equal(count, 1, 'found this one')

    Test.count({ refs: refA } , function (er, count) {
      assert.equal(count, 1, 'found this one')

      Test.count({ 'nestedValues.value': 'Bob' } , function (er, count) {
        assert.equal(count, 1, 'did not find nested values')

        Test.count({ 'nestedRefs._ref': refA } , function (er, count) {
          assert.equal(count, 1, 'did not find nested references')
        })
      })
    })
  })
})

Node.js Mocha Unit Testing error re: Mongoose mocks with Mockgoose, “Error setting TTL index on collection : sessions”

Making this open source application, outrightmental/partybot-web.git on GitHub built on Daftmonk's mighty Yeoman angular-fullstack generator.

I've been trying to wrap my skills around the seemingly hot contemporary problem of doing MongoDB mocks during testing (local and CI) of Node.js.

I'm a fan of Mocha for running and Chai for assertion. After knocking out many early contenders, I'm experimenting now with Mockgoose for mocking behind Mongoose models in lieu of MongoDB.

See also the build pertaining to this issue, in my open source partybot-web CI on Travis

So far, this configuration has been able to successfully run some database operations, proving that Mockgoose is not a complete waste of time. However, this "sessions" table seems to be stumping it.

Please see example local execution below (Ubuntu 12), and let me know if any Node wizards out there have a pearl of wisdom...

Thanks very much!
-Nick

nick@om-ultrabook-ubuntu:~/Development/partybot-web$ mocha test/server/api/incoming/sms.js 
  info  - socket.io started
    Express server listening on port 3000 in development mode
Error: Error setting TTL index on collection : sessions
  at /home/nick/Development/partybot-web/node_modules/connect-mongo/lib/connect-mongo.js:161:23
  at /home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1404:28
  at /home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1542:30
  at /home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:159:22
  at commandHandler (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:678:48)
  at /home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1806:9
  at __executeQueryCommand (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1636:44)
  at Db._executeQueryCommand (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1805:7)
  at Cursor.nextObject (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:729:13)
  at Cursor.toArray (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:158:10)
  at Cursor.toArray (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/scope.js:10:20)
  at /home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1541:65
  at Db.collection (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:495:44)
  at Db.indexInformation (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1539:8)
  at Db.ensureIndex (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1403:8)
  at Collection.ensureIndex (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/collection/index.js:65:11)
  at /home/nick/Development/partybot-web/node_modules/connect-mongo/lib/connect-mongo.js:159:29
  at Db.collection (/home/nick/Development/partybot-web/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:495:44)
  at MongoStore._get_collection (/home/nick/Development/partybot-web/node_modules/connect-mongo/lib/connect-mongo.js:150:17)
  at MongoStore.set (/home/nick/Development/partybot-web/node_modules/connect-mongo/lib/connect-mongo.js:262:12)
  at Session.save (/home/nick/Development/partybot-web/node_modules/express/node_modules/connect/node_modules/express-session/session/session.js:63:25)
  at ServerResponse.res.end (/home/nick/Development/partybot-web/node_modules/express/node_modules/connect/node_modules/express-session/index.js:304:19)
  at twilioResponse (/home/nick/Development/partybot-web/lib/controllers/incoming.js:19:7)
  at Promise.<anonymous> (/home/nick/Development/partybot-web/lib/controllers/incoming.js:58:5)
  at Promise.<anonymous> (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/mpromise/lib/promise.js:177:8)
  at Promise.EventEmitter.emit (events.js:98:17)
  at Promise.emit (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/mpromise/lib/promise.js:84:38)
  at Promise.fulfill (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/mpromise/lib/promise.js:97:20)
  at handleSave (/home/nick/Development/partybot-web/node_modules/mongoose/lib/model.js:133:13)
  at /home/nick/Development/partybot-web/node_modules/mongoose/lib/utils.js:408:16
  at /home/nick/Development/partybot-web/node_modules/mockgoose/lib/Collection.js:116:13
  at Object.validateOptions [as validate] (/home/nick/Development/partybot-web/node_modules/mockgoose/lib/validation/Validation.js:40:5)
  at Collection.insert (/home/nick/Development/partybot-web/node_modules/mockgoose/lib/Collection.js:110:20)
  at model.save (/home/nick/Development/partybot-web/node_modules/mongoose/lib/model.js:190:21)
  at model._done (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/hooks/hooks.js:59:24)
  at _next (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/hooks/hooks.js:52:28)
  at fnWrapper (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/hooks/hooks.js:159:8)
  at model.<anonymous> (/home/nick/Development/partybot-web/lib/models/message.js:31:3)
  at _next (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/hooks/hooks.js:50:30)
  at fnWrapper (/home/nick/Development/partybot-web/node_modules/mongoose/node_modules/hooks/hooks.js:159:8)
  at complete (/home/nick/Development/partybot-web/node_modules/mongoose/lib/document.js:974:5)
  at /home/nick/Development/partybot-web/node_modules/mongoose/lib/document.js:965:20
  at ObjectId.SchemaType.doValidate (/home/nick/Development/partybot-web/node_modules/mongoose/lib/schematype.js:603:22)
  at /home/nick/Development/partybot-web/node_modules/mongoose/lib/document.js:956:9
  at process._tickCallback (node.js:415:13)
GET /api/incoming/sms 200 21ms
․db connection open
POST /api/incoming/sms 200 6ms

Support for nested $in queries

Got another one for ya :) $in works for non-nested properties, but fails when the property is nested. Here is a failing test:

var mockgoose = require('mockgoose')
var mongoose = require('mongoose')
mockgoose(mongoose)
var assert = require('assert')

var schema = new mongoose.Schema({
 value: String,
 nested: {
   value: String
 }
})

var Test = mongoose.model('Test', schema);

Test.create({ 'value': 'Test', 'nested.value': 'Test' }, function (er, test) {
 Test.findOne({ 'value': { $in : ['Test'] } } , function (er, result) {
   assert.ok(!er, 'no error')
   assert.ok(result, 'non-nested works!')

   Test.findOne({ 'nested.value': { $in : ['Test'] } } , function (er, result) {
     assert.ok(!er, 'no error')
     assert.ok(result, 'nested does not')
   })
 })
})

BTW, thanks for quick turnaround on these!

Count operation is throwing an except

For example -
MyCollection.count({x: '25'}) throws an exception.

Works with regular operation through mongoose so I know the query is fine.

     TypeError: undefined is not a function
   Stacktrace:
     TypeError: undefined is not a function
    at /Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:180:17
    at Object.result.toArray (/Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:99:21)
    at /Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:179:21
    at Collection.find (/Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:102:13)
    at Collection.count (/Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:175:14)
    at Query.count (/Users/nukulb/src/hubba-node/node_modules/mongoose/lib/query.js:1649:20)
    at Function.count (/Users/nukulb/src/hubba-node/node_modules/mongoose/lib/model.js:1106:16)

Is there a way to disconnect?

I'm having a problem where my tests are hanging because of the open 'connection' to mockgoose. The tests run, pass, but never exit. If I was utilizing a live mongoose database I'd do something like this:

afterEach(function() {
  mongoose.connection.close();
});

But it doesn't appear that action does anything to help close down the process. Is there a helper method or a strategy I'm missing - or is this something that needs to be implemented?

Needs an "unmock" method

Because Node will only require a module once globally in a process instance, when Mockgoose "infects" mongoose, it causes all future calls to Mongoose to be mocked. This is fine most of the time, but I have a specific (not uncommon) usecase where this is problematic:

My express app has a suite of unit tests (testing Mongoose models) and a suite of integration tests (testing http, controllers, and mongoose). I use mockgoose for the unit tests, but a real Mongo database for the integration tests. Running both tests in the same call to mocha will fail because there is no way to tell mockgoose to "unmock" mongoose.

Does this make sense? Am I misunderstanding something? Thanks :)

Mongoose 3.8.9 compatibility issue

Since mongoose 3.8.9 (ok on 3.8.8), my tests failed on finding documents by key or nested key. ObjectId comparison seems to be source of problem.

This call return document undefined :
Achievement.findOne({'user_id': user._id, 'modules.currentChapter_id' : slide.chapter_id}, function(err, achievement){

Mockgoose needs stream support

var stream = Model.find().stream();

stream.on('data', function (doc) {
  if (somethingHappened) {
    this.pause()

    var self = this
    return bakeSomePizza(function () {
      self.resume()
    })
  }

  res.write(doc)
})

stream.on('error', function (err) {
  // handle err
})

stream.on('close', function () {
  // all done
})

right now following error is thrown

TypeError: Object #<Object> has no method 'nextObject'
    at QueryStream.__next (/Users/nukulb/src/hubba-node/node_modules/mongoose/lib/querystream.js:162:16)
    at QueryStream._next (/Users/nukulb/src/hubba-node/node_modules/mongoose/lib/querystream.js:145:15)
    at /Users/nukulb/src/hubba-node/node_modules/mongoose/lib/querystream.js:118:10
    at Collection.find (/Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:102:13)
    at QueryStream._init (/Users/nukulb/src/hubba-node/node_modules/mongoose/lib/querystream.js:115:20)
    at /Users/nukulb/src/hubba-node/node_modules/mongoose/lib/querystream.js:59:10
    at process._tickDomainCallback (node.js:459:13)

mongoose.connect with 3 parameters causes TypeError

I'm working with a project that has uses the connect function and because an options argument is passed in the mockgoose hook crashes.

/vagrant/src/sub/node_modules/mockgoose/Mockgoose.js:31
openListener(null, connection);
^
TypeError: object is not a function
at /vagrant/src/sub/node_modules/mockgoose/Mockgoose.js:31:17
at NativeConnection.Connection.error (/vagrant/src/sub/node_modules/mongoose/lib/connection.js:381:24)
at /vagrant/src/sub/node_modules/mongoose/lib/connection.js:409:14
at /vagrant/src/sub/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:56:21
at /vagrant/src/sub/node_modules/mongodb/lib/mongodb/db.js:267:16
at null. (/vagrant/src/sub/node_modules/mongodb/lib/mongodb/connection/server.js:550:7)
at EventEmitter.emit (events.js:106:17)
at null. (/vagrant/src/sub/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
at EventEmitter.emit (events.js:98:17)
at Socket. (/vagrant/src/sub/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)

This problem comes from the connection setup which looks like this:
mongoose.connect(config.db.mongodb.connection_string, config.db.mongodb.options, /callback.../ ...);

I changed line 49 of Mockgoose.js to:
mongoose.connect= function(address, options, callback){

and my test no longer caused that error. However, I haven't yet been able to save a test record. I'm not sure if that is related.

Cannot find module 'node-uuid'

I get the following error when running my node/express server. Why is code being loaded from mockgoose's test directory?

What's really odd is that I get this error even when I remove references to mockgoose from my project (but leave the module in the node_modules directory.)

/usr/local/bin/node server.js

module.js:340
    throw err;
          ^
Error: Cannot find module 'node-uuid'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/matt/project/node_modules/mockgoose/test/models/ChildModel.js:2:12)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

Process finished with exit code 8

Save doesn't work on Nested Arrays

Document

name: 'MyName',
friends: [{
      name: 'MyFriend',
      books: [{
            name: 'Book1',
            pages: 145
      }]
}]

now

Model.find({name: 'MyName' }, function (err, doc) {
//insert a new book
doc[0].books.push({name:'Book2', page: 111});

     doc.save(function (err) {
            console.log('New Book NOT saved but its not')
     });

});

Save doesn't work with nested arrays.

Positional Operator misbehaves

When using a positional operator with an update, it seems to not work.
http://docs.mongodb.org/manual/reference/operator/update/positional/

Example-

var ProductSchema = new Schema({
    name: String,
    photos: [
        {
            location: String,
            bucket: String,
            key: String,
            etag: String
        }
    ]
});

Update call

Product.update({ _id: 'some_product_id', 'photos._id': 'some_photo_id' },{
        $set: {
            'photos.$.location': photo.location
        }
    },
    function (err, num) {
        console.log(err, num);
        }
    });

So even though update returns with no errors and it says that num=1 which should mean 1 record is updated. Despite that when go to fetch the updated record using a findById the product returned doesn't have the updated info.

    Product.findById('some_product_id', function (err, product) {
       console.log(err, product);
    });

Any help or workarounds would be appreciated.

Connection should emit on events

According to the API docs for Connection, the connection object should emit a number of events. A few important ones to consider supporting are 'open' and 'error', since some applications may wait for one of these events before proceeding.

var connection = mongoose.createConnection(mongoUrl);
connection.on('open', function() { console.log('OPEN!'); });
connection.on('error', function() { console.log('ERROR!'); });

Support for the aggregation Framework

Looking for support for the aggregation framework.
http://docs.mongodb.org/manual/core/aggregation-introduction/
With the aggregation framework comes a huge set awesome operators that make the aggregation framework very useful
an example of an operator can be found here
http://docs.mongodb.org/manual/reference/operator/aggregation/project/
On the side bar of the above link you can find many other operators.

Example product schema

var ProductSchema = new Schema({
    name: String,
    attributes: [
        {
            k: String,
            v: String
        }
    ]
});

The follow query will return all products that have the name 'dav' in them and return the number of attributes in those products.

    var x = new RegExp('dav');
    Product
    .aggregate(
        [
               {
                   $match: { name: {$regex: x}},
                },
                {
                    $unwind: '$attributes'
                },
                {
                    $group: { _id: "$_id", num: { $sum: 1 }}
                },
                {
                    $sort: { num: -1}
                },
                {
                    $limit: 3
                }
        ],
    function (err, products) {
        console.log(products);
        console.log('Read ' + products.length + ' in ');
    });

Output

[ { _id: 531a2474ed30a70000000010, num: 10 },
  { _id: 531a44c35828f200000000c0, num: 3 } ]

$all comparison fails with ObjectIds

Due to $all using _.contains to do the $all operation, the ObjectIds are not strictly equal to each other.

var MySchema = Schema({
    children: [{type: Schema.Types.ObjectId}]
});

var myId = Schema.Types.ObjectId().toString();
MySchema.create({children: [myId]}, function(err, result) {
    MySchema.find({children: {$all: [myId]}}, function(err, result) {
        if (!result) throw new Error();
    });
});

Support queries on doc arrays

Seems like it shouldn't be too painful to add. I can submit a PR if you'd like.

E.g. here is a failing test:

var mockgoose = require('mockgoose')
var mongoose = require('mongoose')
mockgoose(mongoose)
var assert = require('assert')

var schema = new mongoose.Schema({ names: [] })
var Test = mongoose.model('Test', schema);

Test.create({ names: ['one', 'two'] }, function (er, test) {
  Test.findOne({ names: 'one' } , function (er, result) {
    assert.ok(!er, 'no error')
    assert.ok(result, 'expecting a result')
  })
})

Support for $ne queries

Hey @mccormicka, another one for ya (and one more on the way).

var mockgoose = require('mockgoose')
var mongoose = require('mongoose')
mockgoose(mongoose)
var assert = require('assert')

var schema = new mongoose.Schema({
  value: String
})

var Test = mongoose.model('Test', schema);

Test.create({ value: 'Foo' }, function (er, test) {
  Test.create({ value: 'Baz' }, function (er, test) {
    Test.count({ value: { $ne: 'Baz' } } , function (er, count) {
      assert.ok(!er, 'no error')
      assert.equal(count, 1, 'expect one')
    })

    Test.findOne({ value: { $ne: 'Baz' } } , function (er, test) {
      assert.ok(!er, 'no error')
      assert.equal(test && test.value, 'Foo', 'expect Foo record')
    })
  })
})

mockgoose.reset('schema name'); not working as expected

mockgoose.reset(); works as expected, but when I call reset with a schema name, it doesn't delete the models in the given schema.

  1. I have a User schema
  2. I create some models: User.create({ field: 'value' }, cb);
  3. I call mockgoose.reset('User')
  4. I call User.find(), and the previously created users are still returned in the callback instead of giving an empty array as expected

Callbacks are nested good, so it is not an async issue.
npm ls output:

├─┬ [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│   ├── [email protected]
│   └── [email protected]

Unexpected behavior using .populate()

Using: [email protected], [email protected]

Given the following mongoose schema and model

var UserSchema = new mongoose.Schema({
    name: String,
    friends: [{ type: ObjectId, ref: 'User'}]
});
var User = mongoose.model('User', UserSchema);

lets pretend the following data exists for the User model. The _id values are just for illustration, they are supposed to be real ObjectId's

User 1: { _id: ObjectId_1, name: 'User 1', friends: [] }
User 2: { _id: ObjectId_2, name: 'User 2', friends: [] }
User 3: { _id: ObjectId_3, name: 'User 3', friends: [ ObjectId_1, ObjectId_2 ] }

The following example uses Mongoose only (no Mockgoose)

User.findOne({name: 'User 3'}).populate('friends').exec(function(err, user) {
    // user.name is 'User 3'
    // user.friends contains two User objects (as expected)
    User.findOne({name: 'User 3'}, function(err, user) {
        // user.name is 'User 3'
        // user.friends contains 2 ObjectId's (as I would expect)
    });
});

The following example uses Mockgoose

...
mockgoose(mongoose); // I do this at the very beginning
...
User.findOne({name: 'User 3'}).populate('friends').exec(function(err, user) {
    // user.friends contains two User objects (as expected)
    User.findOne({name: 'User 3'}, function(err, user) {
        // user.friends ALSO contains 2 User objects. I would expect 2 ObjectId's
    });
});

Not sure if I am doing something wrong here. Feedback would be appreciated.

Sorting on fields that don't exist throws an error

Try to sort on a field that doesn't actually exist in some documents

Collection

{ x: 'Name', y: 1}
{ x: 'Name2'}

If you sort collection on y, it will thrown the following error.

   Message:
     TypeError: Cannot call method 'localeCompare' of undefined
   Stacktrace:
     TypeError: Cannot call method 'localeCompare' of undefined
    at /Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/options/Sort.js:50:27
    at Array.sort (native)
    at sortAlpha (/Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/options/Sort.js:49:15)
    at /Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/options/Sort.js:17:21
    at Function.forIn (/Users/nukulb/src/hubba-node/node_modules/mockgoose/node_modules/lodash/dist/lodash.js:1805:15)
    at sortItems (/Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/options/Sort.js:8:11)
    at Object.applyOptions (/Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/options/Options.js:12:17)
    at Collection.find (/Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:92:26)
    at Query.execFind (/Users/nukulb/src/hubba-node/node_modules/mongoose/lib/query.js:1528:20)
    at Query.find (/Users/nukulb/src/hubba-node/node_modules/mongoose/lib/query.js:208:15)
    at Query.exec (/Users/nukulb/src/hubba-node/node_modules/mongoose/lib/query.js:175:16)
    at Object.exports.getUserTree (/Users/nukulb/src/hubba-node/lib/controllers/productTree.js:53:75)
    at null.<anonymous> (/Users/nukulb/src/hubba-node/test/backend/controllers/productTree.js:694:33)

select key in array

I'm having a strange issue with mockgoose.

I write the following mongoose request (in my data model, modules is an array of object):

Model
        .where({ "user_id": userId, "modules.state": "done" })
        .select("id level modules._id modules.status modules.state")
        .exec(/* ... */);

And I get back an object looking like this:

{
  "id": "<some_id>",
  "level": 3,
  "modules": [ {} ]
}

There are no keys in the objects inside modules. I believe this is a bug in mockgoose because this works properly in mongo / barebone mongoose.

Save not implemented in lib/collection.js, but readme says it is supported.

Hi,

I am using mockgoose and loving it (i love having controllable seams to test, which this provides). I was testing validation of one of my domain models and save didn't seem to be working.

When I pulled the source, I did notice in comments you said this was unimplemented. That is totally fine (if I get time, I would love to contribute if you will tell me how).

Anyway, this bug is not so much a problem using mockgoose, just a documentation issue with the readme. Nothing big.

Thanks!

Support matching of subdocuments and arrays using dot notation

Mongoose and the MongoDB query engine allow you to match subdocuments and arrays using a handy dot notation:

As example, consider the following Customer documents:

[
  {
    "_id": 1,
    "name": "Joe Customer",
    "orders": [
      {
        "date": "2014-04-01T00:00:00.000Z",
        "amount": 100
      }, 
      {
        "date": "2014-04-02T00:00:00.000Z",
        "amount": 50
      }
    ]
  },
  {
    "_id": 2,
    "name": "Bob Customer",
    "orders": [
      {
        "date": "2014-04-10T00:00:00.000Z",
        "amount": 75
      }, 
      {
        "date": "2014-04-11T00:00:00.000Z",
        "amount": 25
      }
    ]
  },
  {
    "_id": 3,
    "name": "Bob Customer",
    "orders": [
      {
        "date": "2014-04-06T00:00:00.000Z",
        "amount": 100
      }
    ]
  }
]

We should be able find all customers who have orders with amounts = $100 with the following Mongoose code:

Customer.find({ 'orders.amount': 100 }, {}, function (err, docs) {
  // do something with the customers
});

Mockgoose currently doesn't support queries with this syntax. If you use it, your queries always return zero docs.

Model.count() issue

Was going to submit a failing test but was having trouble getting the test runner to complete. Seems like Model.count() is broken. Here is my test. I am running it against Mongoose 3.8.2. The callback always seems to be set as an empty object. I can submit a PR if it'd help out.

var mongoose = require('mongoose')
var mockgoose = require('mockgoose')
mockgoose(mongoose)

var schema = new mongoose.Schema({ name: String })
var Test = mongoose.model('Test', schema)

Test.count(console.error)

Produces:

/Users/wavded/Projects/Mockgoose/lib/Collection.js:178
                callback(err, results.length);
                ^
TypeError: object is not a function
    at /Users/wavded/Projects/Mockgoose/lib/Collection.js:178:17
    at Object.result.toArray (/Users/wavded/Projects/Mockgoose/lib/Collection.js:98:21)
    at /Users/wavded/Projects/Mockgoose/lib/Collection.js:177:21
    at Collection.find (/Users/wavded/Projects/Mockgoose/lib/Collection.js:101:13)
    at Collection.count (/Users/wavded/Projects/Mockgoose/lib/Collection.js:173:14)
    at NodeCollection.count (/Users/wavded/Projects/Mockgoose/node_modules/mongoose/node_modules/mquery/lib/collection/node.js:45:19)
    at Query.count (/Users/wavded/Projects/Mockgoose/node_modules/mongoose/node_modules/mquery/lib/mquery.js:1676:20)
    at Query.count (/Users/wavded/Projects/Mockgoose/node_modules/mongoose/lib/query.js:1201:27)
    at Function.count (/Users/wavded/Projects/Mockgoose/node_modules/mongoose/lib/model.js:1067:13)
    at Object.<anonymous> (/Users/wavded/Projects/Mockgoose/example.js:8:6)

Feature request: $pushAll

Hi,

i really like your module and wan't to use it in my projects. One problem I have, and i need your advice, how i can implement the code.

I use the push()&save() a lot, but mockgoose doesn't like it. And quit with

[Operations.js]: Mockgoose currently does not support the $pushAll operation

Can you point me in a direction, how i can fix this?

This is my code:

company.users.push("foo");
company.save(callback);

Thanks a lot.

$or with regular expression

Hi,
looks like this combination does not working (in mongoose everything is okay)

regexp = new RegExp(...);
query = this.find({ $or: [{ first: regexp }, { last: regexp }] });

createConnection do not fire connected event

[email protected], [email protected]
this is my code

var mongoose = new require('mongoose');
var mockgoose = require("mockgoose");
mockgoose(mongoose);
...
var conn = mongoose.createConnection(uri, options);
conn.once('connected', function() {
    log.info('[DB] [mongo] ' + uri + ' connected, schema: ' + name);
});
conn.on('error', function(err) {
    log.error('[DB] [mongo] ' + uri + " connect error: " + err);
});

Save doesn't work when removing or updating an item in nested array

Document

name: 'MyName',
friends: [{
      name: 'MyFriend',
      books: [{
            name: 'Book1',
            pages: 145
      },{
            name: 'Book2',
            pages: 300
      }]
}]

now

Model.find({name: 'MyName' }, function (err, doc) {
         //remove a new book
         doc[0].books.pop(); // remove case
         doc[0].books[0].name = 'Book2 - Edited'; //update case

         doc.save(function (err) {

               console.log('Book2 not updated and Book1 not removed');
         });
});

After the last bug fix, adding a new item to a nest array works but, removing or updating an item does not work.

Mocking errors on finding

Hi,

first of all, great project, thanks, it helps a lot.

Is there any possibility to mock error on finding model?

AndOperation file missing

Not sure exactly what is happening but in 1.7.5 the AndOperation.js file is missing so I get a fatal error. I tested in 1.7.4 and the file is there and everything seems fine, even deleted the entire directory and reinstalled. Any ideas as to what could cause this?

Mockgoose Error while updating nested arrays using positional operator

Say you have a document like this

{
p: 'SomeId'
n: 'Some Name',
grps: [
    grpId:'SomeGrpId'
    n: 'Some Group Name',
    attrs: [{
          attrId: 'SomeAttrId'
    }]
]
}

Running the following query

update({ p : 'SomeId', 'grps.grpId' : 'SomeGrpId' }, {
     '$push' : {
           'grps.$.attrs': {
                attrId: 'SomeNewAttrId'
            }
       }
}, function (err) {
});

throws this error

TypeError: Cannot call method 'push' of undefined
    at /Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/operations/PushOperation.js:25:18
    at Function.forIn (/Users/nukulb/src/hubba-node/node_modules/mockgoose/node_modules/lodash/dist/lodash.js:1805:15)
    at pushOperation (/Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/operations/PushOperation.js:11:7)
    at /Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:227:31
    at Function.forIn (/Users/nukulb/src/hubba-node/node_modules/mockgoose/node_modules/lodash/dist/lodash.js:1805:15)
    at updateResult (/Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:226:11)
    at /Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:220:13
    at Function.forEach (/Users/nukulb/src/hubba-node/node_modules/mockgoose/node_modules/lodash/dist/lodash.js:3017:15)
    at updateResults (/Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:219:11)
    at updateFoundItems (/Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:209:13)
    at /Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:144:21
    at Object.result.toArray (/Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:99:21)
    at /Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:128:21
    at Collection.find (/Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:102:13)
    at Collection.update (/Users/nukulb/src/hubba-node/node_modules/mockgoose/lib/Collection.js:124:14)
    at Query.update (/Users/nukulb/src/hubba-node/node_modules/mongoose/lib/query.js:1763:20)
    at Function.update (/Users/nukulb/src/hubba-node/node_modules/mongoose/lib/model.js:1610:16)

$Pull does not work with nested arrays and positional operator

Say you have a document like this

{
p: 'SomeId'
n: 'Some Name',
grps: [
    grpId:'SomeGrpId'
    n: 'Some Group Name',
    attrs: [{
          attrId: 'SomeAttrId'
    }]
]
}

Running the following query

update({ { p: 'SomeId' , 'grps._id': 'SomeGrpId' }, {
     '$pull : {
           'grps.$.attrs': {
                attrId: attrId
            }
       }
}, function (err) {
});
Does not perform the update but also does not throw an error.

update + overwrite

I'm using in my app something like:

var someQuery = {_id: '...'};
var someDoc = {
  attr: 'attr',
  attr2: 'attr2'
};
Model.update(someQuery, someDoc, {upsert: true, overwrite: true});

I need it because I get data from an external source that might contain less attributes than the previous data in DB. i want those attributes to be removed. If you don't provide overwrite: true to mongoose, it silently convert each call into a $set operation. With this option, it does suppress this behaviour.

My problem is that right now, mockgoose is replying:

Mockgoose currently does not support the attr operation
Mockgoose currently does not support the attr2 operation

Multi instances of mongoose

How to work with multi instances of mongoose? Seems like, if I mock two instances, both will share the same data (db.js). I think if the mockgoose create one data per mongoose or connectionString, they will work better for me.

What do you think?

Can't install on Windows

Postinstall script can't execute and windows du to unknown syntax

if [ -d node_modules/jasmine-node ]; then cd node_modules/jasmine-node && npm install; fi

-d était inattendu.
npm ERR! [email protected] postinstall: if [ -d node_modules/jasmine-node ]; then cd node_modules/jasmine-node && npm install; fi
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is most likely a problem with the mockgoose package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! if [ -d node_modules/jasmine-node ]; then cd node_modules/jasmine-node && npm install; fi
npm ERR! You can get their info via:
npm ERR! npm owner ls mockgoose
npm ERR! There is likely additional logging output above.

npm ERR! System Windows_NT 6.1.7600
npm ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install"
npm ERR! cwd D:\dev\coorpAcademy\coorpacademy
npm ERR! node -v v0.10.23
npm ERR! npm -v 1.3.17
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! D:\dev\coorpAcademy\coorpacademy\npm-debug.log
npm ERR! not ok code 0

FindOneAndUpdate issue

I'm running into an issue where when I run a findOneAndUpdate the update doesn't process the dot syntax so I get a top level key instead of an embedded object. An example of what I mean is this:

    User.findOneAndUpdate(
        {
            'access_token.key' : token
        },
        {
            'access_token.expiration': null
        },
        function(err, user) {
             // Here user has a key of 'access_token.expiration': null instead of an embedded obj of access_token:{ expiration: null }
        }
    );

This syntax works for me in Mongoose so I'm assuming it's either an issue or a feature that isn't supported yet. Let me know if you need more info from me.

Thanks!
Chris

Errors when running tests

Sorry for bugging you at this stage but i'm getting some errors when I run npm test. They are nothing to do with my PR #27 , even though travis did seem to have a few issues (and not report a fail) https://travis-ci.org/mccormicka/Mockgoose/jobs/20453061

Here is the output of the npm test: (failures only)

Failures:

  1) Connection Tests Connect Connection should always be the same instance
   Message:
     TypeError: Cannot read property 'connection' of undefined
   Stacktrace:
     TypeError: Cannot read property 'connection' of undefined
    at /apps/Mockgoose/Mockgoose.js:111:50
    at NativeConnection.Connection.error (/apps/Mockgoose/node_modules/mongoose/lib/connection.js:388:24)
    at NativeConnection.Connection.open (/apps/Mockgoose/node_modules/mongoose/lib/connection.js:212:10)
    at Mongoose.connect [as originalConnect] (/apps/Mockgoose/node_modules/mongoose/lib/index.js:211:15)
    at Mongoose.mongoose.connect (/apps/Mockgoose/Mockgoose.js:110:51)
    at null.<anonymous> (/apps/Mockgoose/test/Connectin.spec.js:99:29)
    at null.<anonymous> (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/async-callback.js:45:37)
    at jasmine.Block.execute (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1198:17)
    at jasmine.Queue.next_ (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2238:31)
    at onComplete (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2234:18)

  2) Connection Tests Connect Be able to connect with just a host and database and port and options and callback
   Message:
     TypeError: Cannot read property 'connection' of undefined
   Stacktrace:
     TypeError: Cannot read property 'connection' of undefined
    at /apps/Mockgoose/Mockgoose.js:111:50
    at NativeConnection.Connection.error (/apps/Mockgoose/node_modules/mongoose/lib/connection.js:388:24)
    at NativeConnection.Connection.open (/apps/Mockgoose/node_modules/mongoose/lib/connection.js:212:10)
    at Mongoose.connect [as originalConnect] (/apps/Mockgoose/node_modules/mongoose/lib/index.js:211:15)
    at Mongoose.mongoose.connect (/apps/Mockgoose/Mockgoose.js:110:51)
    at null.<anonymous> (/apps/Mockgoose/test/Connectin.spec.js:104:22)
    at null.<anonymous> (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/async-callback.js:45:37)
    at jasmine.Block.execute (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1198:17)
    at jasmine.Queue.next_ (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2238:31)
    at null._onTimeout (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2228:18)

  3) Connection Tests Connect Should NOT return an error when connecting to Mockgoose through connect
   Message:
     TypeError: Cannot read property 'connection' of undefined
   Stacktrace:
     TypeError: Cannot read property 'connection' of undefined
    at /apps/Mockgoose/Mockgoose.js:111:50
    at NativeConnection.Connection.error (/apps/Mockgoose/node_modules/mongoose/lib/connection.js:388:24)
    at NativeConnection.Connection.open (/apps/Mockgoose/node_modules/mongoose/lib/connection.js:212:10)
    at Mongoose.connect [as originalConnect] (/apps/Mockgoose/node_modules/mongoose/lib/index.js:211:15)
    at Mongoose.mongoose.connect (/apps/Mockgoose/Mockgoose.js:110:51)
    at null.<anonymous> (/apps/Mockgoose/test/Connectin.spec.js:112:22)
    at null.<anonymous> (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/async-callback.js:45:37)
    at jasmine.Block.execute (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1198:17)
    at jasmine.Queue.next_ (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2238:31)
    at onComplete (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2234:18)

  4) Connection Tests Connect Be able to connect with just a host
   Message:
     Expected function not to throw an exception , but it threw Cannot read property 'connection' of undefined
   Stacktrace:
     Error: Expected function not to throw an exception , but it threw Cannot read property 'connection' of undefined
    at new jasmine.ExpectationResult (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:114:32)
    at null.toThrow (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1369:29)
    at null.<anonymous> (/apps/Mockgoose/test/Connectin.spec.js:123:20)
    at null.<anonymous> (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/async-callback.js:45:37)
    at jasmine.Block.execute (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1198:17)
    at jasmine.Queue.next_ (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2238:31)
    at onComplete (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2234:18)
    at jasmine.WaitsForBlock.execute (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2764:5)
    at null._onTimeout (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2778:12)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

  5) Connection Tests Connect Be able to connect with just a host
   Message:
     timeout: timed out after 5000 msec waiting for spec to complete
   Stacktrace:
     undefined

  6) Connection Tests Connect Be able to connect with just a host and callback
   Message:
     TypeError: Cannot read property 'connection' of undefined
   Stacktrace:
     TypeError: Cannot read property 'connection' of undefined
    at /apps/Mockgoose/Mockgoose.js:111:50
    at NativeConnection.Connection.error (/apps/Mockgoose/node_modules/mongoose/lib/connection.js:388:24)
    at NativeConnection.Connection.open (/apps/Mockgoose/node_modules/mongoose/lib/connection.js:212:10)
    at Mongoose.connect [as originalConnect] (/apps/Mockgoose/node_modules/mongoose/lib/index.js:211:15)
    at Mongoose.mongoose.connect (/apps/Mockgoose/Mockgoose.js:110:51)
    at null.<anonymous> (/apps/Mockgoose/test/Connectin.spec.js:127:22)
    at null.<anonymous> (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/async-callback.js:45:37)
    at jasmine.Block.execute (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1198:17)
    at jasmine.Queue.next_ (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2238:31)
    at onComplete (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2234:18)

  7) Connection Tests Connect Be able to connect with just a host and database
   Message:
     Expected function not to throw an exception , but it threw Cannot read property 'connection' of undefined
   Stacktrace:
     Error: Expected function not to throw an exception , but it threw Cannot read property 'connection' of undefined
    at new jasmine.ExpectationResult (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:114:32)
    at null.toThrow (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1369:29)
    at null.<anonymous> (/apps/Mockgoose/test/Connectin.spec.js:138:20)
    at null.<anonymous> (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/async-callback.js:45:37)
    at jasmine.Block.execute (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1198:17)
    at jasmine.Queue.next_ (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2238:31)
    at onComplete (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2234:18)
    at jasmine.WaitsForBlock.execute (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2764:5)
    at null._onTimeout (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2778:12)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

  8) Connection Tests Connect Be able to connect with just a host and database
   Message:
     timeout: timed out after 5000 msec waiting for spec to complete
   Stacktrace:
     undefined

  9) Connection Tests Connect Be able to connect with just a host and database and callback
   Message:
     TypeError: Cannot read property 'connection' of undefined
   Stacktrace:
     TypeError: Cannot read property 'connection' of undefined
    at /apps/Mockgoose/Mockgoose.js:111:50
    at NativeConnection.Connection.error (/apps/Mockgoose/node_modules/mongoose/lib/connection.js:388:24)
    at NativeConnection.Connection.open (/apps/Mockgoose/node_modules/mongoose/lib/connection.js:212:10)
    at Mongoose.connect [as originalConnect] (/apps/Mockgoose/node_modules/mongoose/lib/index.js:211:15)
    at Mongoose.mongoose.connect (/apps/Mockgoose/Mockgoose.js:110:51)
    at null.<anonymous> (/apps/Mockgoose/test/Connectin.spec.js:142:22)
    at null.<anonymous> (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/async-callback.js:45:37)
    at jasmine.Block.execute (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1198:17)
    at jasmine.Queue.next_ (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2238:31)
    at onComplete (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2234:18)

  10) Connection Tests Connect Be able to connect with just a host and database and port
   Message:
     Expected function not to throw an exception , but it threw Cannot read property 'connection' of undefined
   Stacktrace:
     Error: Expected function not to throw an exception , but it threw Cannot read property 'connection' of undefined
    at new jasmine.ExpectationResult (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:114:32)
    at null.toThrow (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1369:29)
    at null.<anonymous> (/apps/Mockgoose/test/Connectin.spec.js:153:20)
    at null.<anonymous> (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/async-callback.js:45:37)
    at jasmine.Block.execute (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1198:17)
    at jasmine.Queue.next_ (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2238:31)
    at onComplete (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2234:18)
    at jasmine.WaitsForBlock.execute (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2764:5)
    at null._onTimeout (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2778:12)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

  11) Connection Tests Connect Be able to connect with just a host and database and port
   Message:
     timeout: timed out after 5000 msec waiting for spec to complete
   Stacktrace:
     undefined

  12) Connection Tests Connect Be able to connect with just a host and database and port and callback
   Message:
     TypeError: Cannot read property 'connection' of undefined
   Stacktrace:
     TypeError: Cannot read property 'connection' of undefined
    at /apps/Mockgoose/Mockgoose.js:111:50
    at NativeConnection.Connection.error (/apps/Mockgoose/node_modules/mongoose/lib/connection.js:388:24)
    at NativeConnection.Connection.open (/apps/Mockgoose/node_modules/mongoose/lib/connection.js:212:10)
    at Mongoose.connect [as originalConnect] (/apps/Mockgoose/node_modules/mongoose/lib/index.js:211:15)
    at Mongoose.mongoose.connect (/apps/Mockgoose/Mockgoose.js:110:51)
    at null.<anonymous> (/apps/Mockgoose/test/Connectin.spec.js:157:22)
    at null.<anonymous> (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/async-callback.js:45:37)
    at jasmine.Block.execute (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1198:17)
    at jasmine.Queue.next_ (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2238:31)
    at onComplete (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2234:18)

  13) Connection Tests Connect Be able to connect with just a host and database and port and options
   Message:
     Expected function not to throw an exception , but it threw Cannot read property 'connection' of undefined
   Stacktrace:
     Error: Expected function not to throw an exception , but it threw Cannot read property 'connection' of undefined
    at new jasmine.ExpectationResult (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:114:32)
    at null.toThrow (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1369:29)
    at null.<anonymous> (/apps/Mockgoose/test/Connectin.spec.js:168:20)
    at null.<anonymous> (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/async-callback.js:45:37)
    at jasmine.Block.execute (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1198:17)
    at jasmine.Queue.next_ (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2238:31)
    at onComplete (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2234:18)
    at jasmine.WaitsForBlock.execute (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2764:5)
    at null._onTimeout (/apps/Mockgoose/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2778:12)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

  14) Connection Tests Connect Be able to connect with just a host and database and port and options
   Message:
     timeout: timed out after 5000 msec waiting for spec to complete
   Stacktrace:
     undefined

Finished in 38.787 seconds
154 tests, 1008 assertions, 14 failures
0 skipped assertions

$in query runs partial match

Hi,

It looks like $in query runs partial match.
Here's a failing test for this. Cannot push it though.

AccountModel.find({email: {$in: ['valid']}}, function(err,  models){
    expect(err).toBeFalsy();
    expect(models.length).toBe(0);
    done();
});

Mockgoose calls mongoose.createConnection with incorrect arguments

See:

var connection = mongoose.originalCreateConnection.call(mongoose, database, options, function (err) {

mongoose.createConnection requires the first argument to be either a hostname or a URI. Mockgoose is calling it with the database name as the first argument. This causes connection.host to return the database name instead of the host name.

This matters because I'm creating multiple connections based on mongoose.connection.host.

What are your thoughts?

Bug in $not:$lte operator

Given the following collection:

/* 0 */
{
    "start" : ISODate("2000-01-01T01:00:00.000-05:00"),
    "end" : ISODate("2014-06-01T00:00:00.000-05:00")
}

/* 1 */
{
    "start" : ISODate("2014-06-01T00:00:00.000-05:00"),
    "end" : ISODate("2014-06-03T10:00:00.000-05:00")
}

/* 2 */
{
    "start" : ISODate("2014-06-03T10:00:00.000-05:00"),
    "end" : null
}

and the query:

find({end:{$not:{$lte:new Date('6/4/2014')}}})

MongoDB returns record 2. Mockgoose returns no records.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.