Socket
Socket
Sign inDemoInstall

mongoose

Package Overview
Dependencies
Maintainers
4
Versions
888
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose - npm Package Compare versions

Comparing version 1.8.4 to 2.0.0

lib/collection.js

62

examples/schema.js

@@ -13,20 +13,31 @@

var BlogPost = new Schema({
title : String
, slug : String
, date : Date
, comments : [Comments]
});
// recursive embedded-document schema
var Comments = new Schema();
var Comment = new Schema();
Comments.add({
Comment.add({
title : { type: String, index: true }
, date : Date
, body : String
, comments : [Comments]
, comments : [Comment]
});
var BlogPost = new Schema({
title : { type: String, index: true }
, slug : { type: String, lowercase: true, trim: true }
, date : Date
, buf : Buffer
, comments : [Comment]
, creator : Schema.ObjectId
});
var Person = new Schema({
name: {
first: String
, last : String
}
, email: { type: String, required: true, index: { unique: true, sparse: true } }
, alive: Boolean
});
/**

@@ -37,8 +48,8 @@ * Accessing a specific schema type by key

BlogPost.path('date')
.default(function(){
return new Date()
})
.set(function(v){
return v == 'now' ? new Date() : v;
});
.default(function(){
return new Date()
})
.set(function(v){
return v == 'now' ? new Date() : v;
});

@@ -55,2 +66,18 @@ /**

/**
* Methods
*/
BlogPost.methods.findCreator = function (callback) {
return this.db.model('Person').findById(this.creator, callback);
}
BlogPost.statics.findByTitle = function (title, callback) {
return this.find({ title: title }, callback);
}
BlogPost.methods.expressiveQuery = function (creator, date, callback) {
return this.find('creator', creator).where('date').gte(date).run(callback);
}
/**
* Plugins

@@ -62,3 +89,3 @@ */

var key = options.key || 'title';
return function slugGenerator(schema){

@@ -79,1 +106,2 @@ schema.path(key).set(function(v){

mongoose.model('BlogPost', BlogPost);
mongoose.model('Person', Person);
2.0.0 / 2011-08-24
===================
* Added; support for Buffers [justmoon]
* Changed; improved error handling [maelstrom]
* Removed: unused utils.erase
* Fixed; support for passing other context object into Schemas (#234) [Sija]
* Fixed; getters are no longer circular refs to themselves (#366)
* Removed; unused compat.js
* Fixed; getter/setter scopes are set properly
* Changed; made several private properties more obvious by prefixing _
* Added; DBRef support [guille]
* Changed; removed support for multiple collection names per model
* Fixed; no longer applying setters when document returned from db
* Changed; default auto_reconnect to true
* Changed; Query#bind no longer clones the query
* Fixed; Model.update now accepts $pull, $inc and friends (#404)
* Added; virtual type option support [nw]
1.8.4 / 2011-08-21

@@ -3,0 +22,0 @@ ===================

@@ -7,2 +7,2 @@

module.exports = require('./lib/mongoose/');
module.exports = require('./lib/');
{
"name": "mongoose"
, "description": "Mongoose MongoDB ORM"
, "version": "1.8.4"
, "version": "2.0.0"
, "author": "Guillermo Rauch <guillermo@learnboost.com>"

@@ -6,0 +6,0 @@ , "keywords": ["mongodb", "mongoose", "orm", "data", "datastore", "nosql"]

@@ -1,2 +0,2 @@

Mongoose 1.0
Mongoose 2.0
============

@@ -6,3 +6,3 @@

Mongoose is a MongoDB object modeling tool designed to work in an asynchronous
Mongoose is a [MongoDB](http://www.mongodb.org/) object modeling tool designed to work in an asynchronous
environment.

@@ -14,3 +14,3 @@

var Comments = new Schema({
title : String
title : String
, body : String

@@ -21,9 +21,10 @@ , date : Date

var BlogPost = new Schema({
author : ObjectId
author : ObjectId
, title : String
, body : String
, buf : Buffer
, date : Date
, comments : [Comments]
, meta : {
votes : Number
votes : Number
, favs : Number

@@ -33,3 +34,3 @@ }

mongoose.model('BlogPost', BlogPost);
var Post = mongoose.model('BlogPost', BlogPost);
```

@@ -39,3 +40,3 @@

The recommended way is through the excellent NPM:
The recommended way is through the excellent [NPM](http://www.npmjs.org/):

@@ -69,3 +70,3 @@ ```bash

Both `connect` and `createConnection` take a `mongodb://` URI, or the parameters
`host, database, port`.
`host, database, port, options`.

@@ -95,3 +96,3 @@ ```javascript

var BlogPost = new Schema({
author : ObjectId
author : ObjectId
, title : String

@@ -106,11 +107,12 @@ , body : String

* Validators (async and sync)
* Defaults
* Getters
* Setters
* Indexes
* Middleware
* Methods definition
* Statics definition
* Plugins
* [Validators](http://mongoosejs.com/docs/validation.html) (async and sync)
* [Defaults](http://mongoosejs.com/docs/schematypes.html)
* [Getters](http://mongoosejs.com/docs/getters-setters.html)
* [Setters](http://mongoosejs.com/docs/getters-setters.html)
* [Indexes](http://mongoosejs.com/docs/indexes.html)
* [Middleware](http://mongoosejs.com/docs/middleware.html)
* [Methods](http://mongoosejs.com/docs/methods-statics.html) definition
* [Statics](http://mongoosejs.com/docs/methods-statics.html) definition
* [Plugins](http://mongoosejs.com/docs/plugins.html)
* [DBRefs](http://mongoosejs.com/docs/dbrefs.html)

@@ -121,6 +123,7 @@ The following example shows some of these features:

var Comment = new Schema({
name : { type: String, default: 'hahaha' }
name : { type: String, default: 'hahaha' }
, age : { type: Number, min: 18, index: true }
, bio : { type: String, match: /[a-z]/ }
, date : { type: Date, default: Date.now }
, buff : Buffer
});

@@ -130,3 +133,3 @@

Comment.path('name').set(function (v) {
return v.capitalize();
return capitalize(v);
});

@@ -142,3 +145,3 @@

Take a look at the example in `examples/schema.js` for an end-to-end example of
(almost) all the functionality available.
a typical setup.

@@ -154,6 +157,12 @@ ## Accessing a Model

Or just do it all at once
```javascript
var MyModel = mongoose.model('ModelName', mySchema);
```
We can then instantiate it, and save it:
```javascript
var instance = new myModel();
var instance = new MyModel();
instance.my.key = 'hello';

@@ -168,3 +177,3 @@ instance.save(function (err) {

```javascript
myModel.find({}, function (err, docs) {
MyModel.find({}, function (err, docs) {
// docs.forEach

@@ -175,3 +184,3 @@ });

You can also `findOne`, `findById`, `update`, etc. For more details check out
the API docs.
[this link](http://mongoosejs.com/docs/finding-documents.html).

@@ -226,6 +235,6 @@ ## Embedded Documents

Middleware is one of the most exciting features about Mongoose 1.0. Middleware
Middleware is one of the most exciting features about Mongoose. Middleware
takes away all the pain of nested callbacks.
Middleware are defined at the Schema level and are applied when the methods
Middleware are defined at the Schema level and are applied for the methods
`init` (when a document is initialized with data from MongoDB), `save` (when

@@ -296,3 +305,3 @@ a document or embedded document is saved).

this.emit('set', path, val);
// Pass control to the next pre

@@ -311,3 +320,5 @@ next();

next("altered-" + methodArg1.toString(), methodArg2);
}) // pre declaration is chainable
})
// pre declaration is chainable
.pre(method, function secondPre (next, methodArg1, methodArg2) {

@@ -328,6 +339,29 @@ console.log(methodArg1);

### Schema gotcha
`type`, when used in a schema has special meaning within Mongoose. If your
schema requires using `type` as a nested property you must use object notation:
``` javascript
new Schema({
broken: { type: Boolean }
, asset : {
name: String
, type: String // uh oh, it broke. asset will be interpreted as String
}
});
new Schema({
works: { type: Boolean }
, asset : {
name: String
, type: { type: String } // works. asset is an object with a type property
}
});
```
## API docs
You can find the [Dox](http://github.com/visionmedia/dox) generated API docs at
[http://mongoosejs.com](http://mongoosejs.com).
You can find the [Dox](http://github.com/visionmedia/dox) generated API docs
[here](http://mongoosejs.com/docs/api.html).

@@ -339,2 +373,8 @@ ## Getting support

Join #mongoosejs on freenode.
## Driver access
The driver being used defaults to [node-mongodb-native](https://github.com/christkv/node-mongodb-native) and is directly accessible through `YourModel.collection`. **Note**: using the driver directly bypasses all Mongoose power-tools like validation, getters, setters, hooks, etc.
## Mongoose Plugins

@@ -350,4 +390,4 @@

Twitter, Github, and more.
- [mongoose-dbref](https://github.com/goulash1971/mongoose-dbref) - Adds DBRef support
- [mongoose-joins](https://github.com/goulash1971/mongoose-joins) - Adds simple join support
- [mongoose-dbref](https://github.com/goulash1971/mongoose-dbref) - An alternative DBRef option

@@ -358,9 +398,6 @@ ## Contributing to Mongoose

Make a fork of `mongoose`, then clone it in your computer. The `master` branch
contains the current stable release, and the `develop` branch the next upcoming
Make a fork of `mongoose`, then clone it in your computer. The `v2.x` branch
contains the current stable release, and the `master` branch the next upcoming
major release.
If `master` is at `1.0`, `develop` will contain the upcoming `1.1` (or `2.0` if
the `1` branch is nearing its completion).
### Guidelines

@@ -371,3 +408,3 @@

- Before starting to write code, look for existing tickets or create one for
your specifc issue (unless you're addressing something that's clearly broken).
your specific issue (unless you're addressing something that's clearly broken).
That way you avoid working on something that might not be of interest or that

@@ -385,3 +422,3 @@ has been addressed already in a different branch.

Copyright (c) 2010 LearnBoost &lt;dev@learnboost.com&gt;
Copyright (c) 2010-2011 LearnBoost &lt;dev@learnboost.com&gt;

@@ -388,0 +425,0 @@ Permission is hereby granted, free of charge, to any person obtaining

var start = require('./common')
, mongoose = start.mongoose
, Collection = require('mongoose/collection');
, Collection = require('../lib/collection');

@@ -20,7 +20,5 @@ module.exports = {

process.nextTick(function(){
var uri = 'mongodb://localhost/mongoose_test';
db.open(process.env.MONGOOSE_TEST_URI || uri, function(err){
connected = !err;
});
var uri = 'mongodb://localhost/mongoose_test';
db.open(process.env.MONGOOSE_TEST_URI || uri, function(err){
connected = !err;
});

@@ -27,0 +25,0 @@

@@ -36,3 +36,3 @@

db.options.server.should.be.a('object');
db.options.server.auto_reconnect.should.be.false;
db.options.server.auto_reconnect.should.be.true;
db.options.db.should.be.a('object');

@@ -50,3 +50,3 @@ db.options.db.forceServerObjectId.should.be.false;

db.options.server.should.be.a('object');
db.options.server.auto_reconnect.should.be.false;
db.options.server.auto_reconnect.should.be.true;
db.options.db.should.be.a('object');

@@ -64,3 +64,3 @@ db.options.db.forceServerObjectId.should.be.false;

db.options.server.should.be.a('object');
db.options.server.auto_reconnect.should.be.false;
db.options.server.auto_reconnect.should.be.true;
db.options.db.should.be.a('object');

@@ -78,3 +78,3 @@ db.options.db.forceServerObjectId.should.be.false;

db.options.server.should.be.a('object');
db.options.server.auto_reconnect.should.be.false;
db.options.server.auto_reconnect.should.be.true;
db.options.db.should.be.a('object');

@@ -84,6 +84,6 @@ db.options.db.forceServerObjectId.should.be.false;

db = mongoose.createConnection('mongodb://aaron:psw@localhost:27000/fake', { server: { auto_reconnect: true }});
db = mongoose.createConnection('mongodb://aaron:psw@localhost:27000/fake', { server: { auto_reconnect: false }});
db.options.should.be.a('object');
db.options.server.should.be.a('object');
db.options.server.auto_reconnect.should.be.true;
db.options.server.auto_reconnect.should.be.false;
db.options.db.should.be.a('object');

@@ -116,3 +116,3 @@ db.options.db.forceServerObjectId.should.be.false;

db.options.server.should.be.a('object');
db.options.server.auto_reconnect.should.be.false;
db.options.server.auto_reconnect.should.be.true;
db.options.db.should.be.a('object');

@@ -130,3 +130,3 @@ db.options.db.forceServerObjectId.should.be.false;

db.options.server.should.be.a('object');
db.options.server.auto_reconnect.should.be.false;
db.options.server.auto_reconnect.should.be.true;
db.options.db.should.be.a('object');

@@ -144,3 +144,3 @@ db.options.db.forceServerObjectId.should.be.false;

db.options.server.should.be.a('object');
db.options.server.auto_reconnect.should.be.false;
db.options.server.auto_reconnect.should.be.true;
db.options.db.should.be.a('object');

@@ -154,3 +154,3 @@ db.options.db.forceServerObjectId.should.be.false;

var called3 = false;
db = mongoose.createConnection('127.0.0.1', 'faker', 28000, { server: { auto_reconnect: true }}, function () {
db = mongoose.createConnection('127.0.0.1', 'faker', 28000, { server: { auto_reconnect: false }}, function () {
called3 = true;

@@ -163,3 +163,3 @@ });

db.options.server.should.be.a('object');
db.options.server.auto_reconnect.should.be.true;
db.options.server.auto_reconnect.should.be.false;
db.options.db.should.be.a('object');

@@ -181,3 +181,3 @@ db.options.db.forceServerObjectId.should.be.false;

db.options.server.should.be.a('object');
db.options.server.auto_reconnect.should.be.false;
db.options.server.auto_reconnect.should.be.true;
db.options.db.should.be.a('object');

@@ -204,3 +204,3 @@ db.options.db.forceServerObjectId.should.be.false;

db.options.server.should.be.a('object');
db.options.server.auto_reconnect.should.be.false;
db.options.server.auto_reconnect.should.be.true;
db.options.db.should.be.a('object');

@@ -216,3 +216,3 @@ db.options.db.forceServerObjectId.should.be.false;

db.options.server.should.be.a('object');
db.options.server.auto_reconnect.should.be.false;
db.options.server.auto_reconnect.should.be.true;
db.options.db.should.be.a('object');

@@ -235,3 +235,3 @@ db.options.db.forceServerObjectId.should.be.false;

db.options.server.should.be.a('object');
db.options.server.auto_reconnect.should.be.false;
db.options.server.auto_reconnect.should.be.true;
db.options.db.should.be.a('object');

@@ -247,3 +247,3 @@ db.options.db.forceServerObjectId.should.be.false;

db.options.server.should.be.a('object');
db.options.server.auto_reconnect.should.be.false;
db.options.server.auto_reconnect.should.be.true;
db.options.db.should.be.a('object');

@@ -250,0 +250,0 @@ db.options.db.forceServerObjectId.should.be.false;

@@ -11,3 +11,3 @@

, ObjectId = Schema.ObjectId
, Document = require('mongoose/document')
, Document = require('../lib/document')
, DocumentObjectId = mongoose.Types.ObjectId;

@@ -33,3 +33,3 @@

TestDocument.prototype.schema = new Schema({
var schema = TestDocument.prototype.schema = new Schema({
test : String

@@ -40,5 +40,29 @@ , oids : [ObjectId]

, cool : ObjectId
, deep : { x: String }
, path : String
, setr : String
}
, nested2 : {
nested: String
, yup : {
nested : Boolean
, yup : String
, age : Number
}
}
});
schema.virtual('nested.agePlus2').get(function (v) {
return this.nested.age + 2;
});
schema.virtual('nested.setAge').set(function (v) {
this.nested.age = v;
});
schema.path('nested.path').get(function (v) {
return this.nested.age + (v ? v : '');
});
schema.path('nested.setr').set(function (v) {
return v + ' setter';
});
/**

@@ -66,5 +90,17 @@ * Method subject to hooks. Simply fires the callback once the hooks are

, cool : DocumentObjectId.fromString('4c6c2d6240ced95d0e00003c')
, path : 'my path'
}
});
doc.test.should.eql('test');
doc.oids.should.be.an.instanceof(Array);
(doc.nested.age == 5).should.be.true;
DocumentObjectId.toString(doc.nested.cool).should.eql('4c6c2d6240ced95d0e00003c');
doc.nested.agePlus2.should.eql(7);
doc.nested.path.should.eql('5my path');
doc.nested.setAge = 10;
(doc.nested.age == 10).should.be.true;
doc.nested.setr = 'set it';
doc.getValue('nested.setr').should.eql('set it setter');
var doc2 = new TestDocument();

@@ -77,10 +113,6 @@ doc2.init({

, cool : DocumentObjectId.fromString('4cf70857337498f95900001c')
, deep : { x: 'yay' }
}
});
doc.test.should.eql('test');
doc.oids.should.be.an.instanceof(Array);
(doc.nested.age == 5).should.be.true;
DocumentObjectId.toString(doc.nested.cool).should.eql('4c6c2d6240ced95d0e00003c');
doc2.test.should.eql('toop');

@@ -91,5 +123,33 @@ doc2.oids.should.be.an.instanceof(Array);

// GH-366
should.strictEqual(doc2.nested.bonk, undefined);
should.strictEqual(doc2.nested.nested, undefined);
should.strictEqual(doc2.nested.test, undefined);
should.strictEqual(doc2.nested.age.test, undefined);
should.strictEqual(doc2.nested.age.nested, undefined);
should.strictEqual(doc2.oids.nested, undefined);
should.strictEqual(doc2.nested.deep.x, 'yay');
should.strictEqual(doc2.nested.deep.nested, undefined);
should.strictEqual(doc2.nested.deep.cool, undefined);
should.strictEqual(doc2.nested2.yup.nested, undefined);
should.strictEqual(doc2.nested2.yup.nested2, undefined);
should.strictEqual(doc2.nested2.yup.yup, undefined);
should.strictEqual(doc2.nested2.yup.age, undefined);
doc2.nested2.yup.should.be.a('object');
doc2.nested2.yup = {
age: 150
, yup: "Yesiree"
, nested: true
};
should.strictEqual(doc2.nested2.nested, undefined);
should.strictEqual(doc2.nested2.yup.nested, true);
should.strictEqual(doc2.nested2.yup.yup, "Yesiree");
(doc2.nested2.yup.age == 150).should.be.true;
doc2.nested2.nested = "y";
should.strictEqual(doc2.nested2.nested, "y");
should.strictEqual(doc2.nested2.yup.nested, true);
should.strictEqual(doc2.nested2.yup.yup, "Yesiree");
(doc2.nested2.yup.age == 150).should.be.true;
DocumentObjectId.toString(doc2.nested.cool).should.eql('4cf70857337498f95900001c');

@@ -150,6 +210,6 @@

should.strictEqual(doc.doc.test._marked, undefined);
should.strictEqual(doc.doc.nested._marked, undefined);
should.strictEqual(doc.doc.nested.age._marked, undefined);
should.strictEqual(doc.doc.nested.cool._marked, undefined);
should.strictEqual(doc._doc.test._marked, undefined);
should.strictEqual(doc._doc.nested._marked, undefined);
should.strictEqual(doc._doc.nested.age._marked, undefined);
should.strictEqual(doc._doc.nested.cool._marked, undefined);
},

@@ -181,9 +241,10 @@

steps++;
steps.should.eql(3);
setTimeout(function(){
steps.should.eql(4);
}, 50);
}, 10);
setTimeout(function(){
steps++;
done();
}, 100);
}, 110);
next();

@@ -196,7 +257,7 @@ });

steps.should.eql(4);
}, 50);
}, 10);
setTimeout(function(){
steps++;
done();
}, 100);
}, 110);
next();

@@ -471,3 +532,3 @@ });

'MongooseErrors should be instances of Error': function () {
var MongooseError = require('../lib/mongoose/error')
var MongooseError = require('../lib/error')
, err = new MongooseError("Some message");

@@ -480,4 +541,35 @@ err.should.be.an.instanceof(Error);

err.should.be.an.instanceof(Error);
},
'methods on embedded docs should work': function () {
var db = start()
, ESchema = new Schema({ name: String })
ESchema.methods.test = function () {
return this.name + ' butter';
}
ESchema.statics.ten = function () {
return 10;
}
var E = db.model('EmbeddedMethodsAndStaticsE', ESchema);
var PSchema = new Schema({ embed: [ESchema] });
var P = db.model('EmbeddedMethodsAndStaticsP', PSchema);
var p = new P({ embed: [{name: 'peanut'}] });
should.equal('function', typeof p.embed[0].test);
should.equal('function', typeof E.ten);
p.embed[0].test().should.equal('peanut butter');
E.ten().should.equal(10);
// test push casting
p = new P;
p.embed.push({name: 'apple'});
should.equal('function', typeof p.embed[0].test);
should.equal('function', typeof E.ten);
p.embed[0].test().should.equal('apple butter');
db.close();
}
};

@@ -9,4 +9,4 @@

, mongoose = start.mongoose
, random = require('mongoose/utils').random
, Query = require('mongoose/query')
, random = require('../lib/utils').random
, Query = require('../lib/query')
, Schema = mongoose.Schema

@@ -16,2 +16,3 @@ , SchemaType = mongoose.SchemaType

, ObjectId = Schema.ObjectId
, MongooseBuffer = mongoose.Types.Buffer
, DocumentObjectId = mongoose.Types.ObjectId;

@@ -45,2 +46,3 @@

, tags : [String]
, sigs : [Buffer]
, owners : [ObjectId]

@@ -1205,2 +1207,22 @@ , comments : [Comments]

'test finding documents with a specifc Buffer in their array': function () {
var db = start()
, BlogPostB = db.model('BlogPostB', collection);
BlogPostB.create({sigs: [new Buffer([1, 2, 3]),
new Buffer([4, 5, 6]),
new Buffer([7, 8, 9])]}, function (err, created) {
should.strictEqual(err, null);
BlogPostB.findOne({sigs: new Buffer([1, 2, 3])}, function (err, found) {
should.strictEqual(err, null);
found._id.should.eql(created._id);
var query = { sigs: { "$in" : [new Buffer([3, 3, 3]), new Buffer([4, 5, 6])] } };
BlogPostB.findOne(query, function (err, found) {
should.strictEqual(err, null);
db.close();
});
});
});
},
'test limits': function () {

@@ -1471,4 +1493,149 @@ var db = start()

});
},
'buffers find using available types': function () {
var db = start()
, BufSchema = new Schema({ name: String, block: Buffer })
, Test = db.model('Buffer', BufSchema, "buffers");
var docA = { name: 'A', block: new Buffer('über') };
var docB = { name: 'B', block: new Buffer("buffer shtuffs are neat") };
var docC = { name: 'C', block: 'hello world' };
Test.create(docA, docB, docC, function (err, a, b, c) {
should.strictEqual(err, null);
b.block.toString('utf8').should.equal('buffer shtuffs are neat');
a.block.toString('utf8').should.equal('über');
c.block.toString('utf8').should.equal('hello world');
Test.findById(a._id, function (err, a) {
should.strictEqual(err, null);
a.block.toString('utf8').should.equal('über');
Test.findOne({ block: 'buffer shtuffs are neat' }, function (err, rb) {
should.strictEqual(err, null);
rb.block.toString('utf8').should.equal('buffer shtuffs are neat');
Test.findOne({ block: /buffer/i }, function (err, rb) {
err.message.should.eql('Cast to buffer failed for value "/buffer/i"')
Test.findOne({ block: [195, 188, 98, 101, 114] }, function (err, rb) {
should.strictEqual(err, null);
rb.block.toString('utf8').should.equal('über');
Test.findOne({ block: 'aGVsbG8gd29ybGQ=' }, function (err, rb) {
should.strictEqual(err, null);
should.strictEqual(rb, null);
Test.findOne({ block: new Buffer('aGVsbG8gd29ybGQ=', 'base64') }, function (err, rb) {
should.strictEqual(err, null);
rb.block.toString('utf8').should.equal('hello world');
Test.findOne({ block: new MongooseBuffer('aGVsbG8gd29ybGQ=', 'base64') }, function (err, rb) {
should.strictEqual(err, null);
rb.block.toString('utf8').should.equal('hello world');
Test.remove({}, function (err) {
db.close();
should.strictEqual(err, null);
});
});
});
});
});
});
});
});
});
},
'buffer tests using conditionals': function () {
// $in $nin etc
var db = start()
, BufSchema = new Schema({ name: String, block: Buffer })
, Test = db.model('Buffer2', BufSchema, "buffer_"+random());
var docA = { name: 'A', block: new MongooseBuffer([195, 188, 98, 101, 114]) }; //über
var docB = { name: 'B', block: new MongooseBuffer("buffer shtuffs are neat") };
var docC = { name: 'C', block: new MongooseBuffer('aGVsbG8gd29ybGQ=', 'base64') };
Test.create(docA, docB, docC, function (err, a, b, c) {
should.strictEqual(err, null);
a.block.toString('utf8').should.equal('über');
b.block.toString('utf8').should.equal('buffer shtuffs are neat');
c.block.toString('utf8').should.equal('hello world');
Test.find({ block: { $in: [[195, 188, 98, 101, 114], "buffer shtuffs are neat", new Buffer('aGVsbG8gd29ybGQ=', 'base64')] }}, function (err, tests) {
done();
should.strictEqual(err, null);
tests.length.should.equal(3);
});
Test.find({ block: { $in: ['über', 'hello world'] }}, function (err, tests) {
done();
should.strictEqual(err, null);
tests.length.should.equal(2);
});
Test.find({ block: { $in: ['über'] }}, function (err, tests) {
done();
should.strictEqual(err, null);
tests.length.should.equal(1);
tests[0].block.toString('utf8').should.equal('über');
});
Test.find({ block: { $nin: ['über'] }}, function (err, tests) {
done();
should.strictEqual(err, null);
tests.length.should.equal(2);
});
Test.find({ block: { $nin: [[195, 188, 98, 101, 114], new Buffer('aGVsbG8gd29ybGQ=', 'base64')] }}, function (err, tests) {
done();
should.strictEqual(err, null);
tests.length.should.equal(1);
tests[0].block.toString('utf8').should.equal('buffer shtuffs are neat');
});
Test.find({ block: { $ne: 'über' }}, function (err, tests) {
done();
should.strictEqual(err, null);
tests.length.should.equal(2);
});
Test.find({ block: { $gt: 'über' }}, function (err, tests) {
done();
should.strictEqual(err, null);
tests.length.should.equal(2);
});
Test.find({ block: { $gte: 'über' }}, function (err, tests) {
done();
should.strictEqual(err, null);
tests.length.should.equal(3);
});
Test.find({ block: { $lt: new Buffer('buffer shtuffs are neat') }}, function (err, tests) {
done();
should.strictEqual(err, null);
tests.length.should.equal(2);
tests[0].block.toString('utf8').should.equal('über');
});
Test.find({ block: { $lte: 'buffer shtuffs are neat' }}, function (err, tests) {
done();
should.strictEqual(err, null);
tests.length.should.equal(3);
});
var pending = 9;
function done () {
if (--pending) return;
Test.remove({}, function (err) {
db.close();
should.strictEqual(err, null);
});
}
});
}
};

@@ -29,3 +29,3 @@ //Query.prototype.where(criteria, callback)

, mongoose = start.mongoose
, random = require('mongoose/utils').random
, random = require('../lib/utils').random
, Schema = mongoose.Schema

@@ -32,0 +32,0 @@ , _24hours = 24 * 3600 * 1000;

@@ -7,3 +7,3 @@

var should = require('should')
, Promise = require('mongoose/promise');
, Promise = require('../lib/promise');

@@ -98,3 +98,3 @@ /**

, called = 0;
promise.error(new Error('woot'));

@@ -101,0 +101,0 @@

@@ -6,3 +6,3 @@

var Query = require('mongoose/query')
var Query = require('../lib/query')
, start = require('./common')

@@ -9,0 +9,0 @@ , mongoose = start.mongoose

var start = require('./common')
, should = require('should')
, mongoose = start.mongoose
, random = require('mongoose/utils').random
, random = require('../lib/utils').random
, Schema = mongoose.Schema

@@ -6,0 +6,0 @@ , ObjectId = Schema.ObjectId;

@@ -396,2 +396,3 @@

, strings : [String]
, buffers : [Buffer]
, nocast : []

@@ -402,3 +403,3 @@ , mixed : [Mixed]

var oids = Loki.path('oids').cast(['4c54f3453e688c000000001a', new DocumentObjectId]);
oids[0].should.be.an.instanceof(DocumentObjectId);

@@ -416,3 +417,3 @@ oids[1].should.be.an.instanceof(DocumentObjectId);

numbers[1].should.be.a('number');
var strings = Loki.path('strings').cast(['test', 123]);

@@ -426,2 +427,7 @@

var buffers = Loki.path('buffers').cast(['\0\0\0', new Buffer("abc")]);
buffers[0].should.be.an.instanceof(Buffer);
buffers[1].should.be.an.instanceof(Buffer);
var nocasts = Loki.path('nocast').cast(['test', 123]);

@@ -428,0 +434,0 @@

@@ -10,3 +10,3 @@

, Schema = mongoose.Schema
, random = require('mongoose/utils').random
, random = require('../lib/utils').random
, MongooseArray = mongoose.Types.Array;

@@ -13,0 +13,0 @@

@@ -9,4 +9,4 @@

, mongoose = start.mongoose
, EmbeddedDocument = require('mongoose/types/document')
, DocumentArray = require('mongoose/types/documentarray')
, EmbeddedDocument = require('../lib/types/document')
, DocumentArray = require('../lib/types/documentarray')
, Schema = mongoose.Schema

@@ -13,0 +13,0 @@ , SchemaType = mongoose.SchemaType

@@ -9,7 +9,6 @@

, MongooseDocumentArray = mongoose.Types.DocumentArray
, EmbeddedDocument = require('mongoose/types/document')
, DocumentArray = require('mongoose/types/documentarray')
, EmbeddedDocument = require('../lib/types/document')
, DocumentArray = require('../lib/types/documentarray')
, Schema = mongoose.Schema
/**

@@ -16,0 +15,0 @@ * Setup.

@@ -8,5 +8,5 @@

var utils = require('mongoose/utils')
, ObjectId = require('mongoose/types/objectid')
, StateMachine = utils.StateMachine;
var utils = require('../lib/utils')
, StateMachine = require('../lib/statemachine')
, ObjectId = require('../lib/types/objectid')

@@ -25,16 +25,2 @@ /**

'test array erasing util': function(){
function fn(){};
var arr = [fn, 'test', 1]
, arr2 = [fn, 'a', 'b', fn, 'c'];
utils.erase(arr, fn);
arr.should.have.length(2);
arr.should.eql(['test', 1]);
utils.erase(arr2, fn);
arr2.should.have.length(3);
arr2.should.eql(['a', 'b', 'c']);
},
'should detect a path as required if it has been required': function () {

@@ -41,0 +27,0 @@ var ar = new ActiveRoster();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc