Started on node.js+socket.io+mongoDB on the backend for more responsivnes

This commit is contained in:
KasperRT
2015-04-09 00:18:13 +02:00
parent 076f8e821f
commit a8a705bd77
1889 changed files with 322175 additions and 68 deletions

71
server/node_modules/mongojs/test/test-find-and-modify.js generated vendored Executable file
View File

@@ -0,0 +1,71 @@
var insert = require('./insert');
insert('findAndModify', [{
id: 1,
hello: 'you'
}, {
id: 2,
hello: 'other'
}], function(db, t, done) {
// Update and find the old document
db.a.findAndModify({
query: { id: 1 },
update: { $set: { hello: 'world' } },
},
function(err, doc, lastErrorObject) {
t.ok(!err);
t.equal(doc.id, 1);
t.equal(doc.hello, 'you');
t.equal(lastErrorObject.updatedExisting, true);
t.equal(lastErrorObject.n, 1);
// Update and find the new document
db.a.findAndModify({
query: { id: 2 },
'new': true,
update: { $set: { hello: 'me' } }
}, function(err, doc, lastErrorObject) {
t.ok(!err);
t.equal(doc.id, 2);
t.equal(doc.hello, 'me');
t.equal(lastErrorObject.updatedExisting, true);
t.equal(lastErrorObject.n, 1);
// Remove and find document
db.a.findAndModify({
query: { id: 1 },
remove: true
}, function(err, doc, lastErrorObject) {
t.ok(!err);
t.equal(doc.id, 1);
t.equal(lastErrorObject.n, 1);
// Insert document using upsert
db.a.findAndModify({
query: { id: 3 },
update: { id: 3, hello: 'girl' },
'new': true,
upsert: true
}, function(err, doc, lastErrorObject) {
t.ok(!err);
t.equal(doc.id, 3);
t.equal(doc.hello, 'girl');
t.equal(lastErrorObject.updatedExisting, false);
t.equal(lastErrorObject.n, 1);
t.equal(String(lastErrorObject.upserted), String(doc._id));
// Find non existing document
db.a.findAndModify({
query: { id: 0 },
update: { $set: { hello: 'boy' } }
}, function(err, doc, lastErrorObject) {
t.ok(!err);
t.equal(lastErrorObject.n, 0);
done();
});
});
});
});
});
});