-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d3f2d3
commit 25683d1
Showing
3 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Example for insert/update/find/remove users | ||
* | ||
*/ | ||
|
||
var assert = require("assert") | ||
, mongoq = require("../index.js") | ||
, db = mongoq("mongodb://127.0.0.1:27017/mongoqTest") | ||
, User = db.collection("users"); | ||
|
||
User.remove() //clear test date | ||
.done( function() { | ||
User.insert( [{ _id: 1, name: "Jack", age: 22 }, { _id: 2, name: "Lucy", age: 20 }] ) //Add Jack and Lucy | ||
.and( User.insert( { _id: 3, name: "Mike", age: 21 } ) ) //Add Mike synchronous | ||
.and( function(u1, u2) { | ||
// Will find after add Jack, Lucy and Mike | ||
return User.findOne( { name: u2[0]["name"] } ) | ||
} ) | ||
.done( function(u1, u2, u3) { //All be done | ||
assert.deepEqual( u1, [{ _id: 1, name: "Jack", age: 22 }, { _id: 2, name: "Lucy", age: 20 }], "Insert first" ); | ||
assert.deepEqual( u2, [{ _id: 3, name: "Mike", age: 21 }], "insert second" ); | ||
assert.deepEqual( u3, { _id: 3, name: "Mike", age: 21 }, "Find after insert" ); | ||
db.close(); | ||
} ) | ||
.fail( function( err ) { // Any error occur | ||
console.log( err ); | ||
} ); | ||
} ) | ||
.fail( function( err ) { // Faild to remove | ||
console.log( err ); | ||
} ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters