forked from SeanTRobinson/Angular_Mongo_Node-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
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
30a90a1
commit 578e384
Showing
4 changed files
with
74 additions
and
1 deletion.
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,19 @@ | ||
var MongoClient = require('mongodb').MongoClient | ||
MongoClient.connect("mongodb://localhost/", function(err, db) { | ||
var myDB = db.db("astro") | ||
myDB.collection("nebulae", function(err, nebulae) { | ||
nebulae.find( {type: "supernova"}, function(err, items) { | ||
items.toArray(function(err, itemArr) { | ||
console.log("Before Modify: "); | ||
console.log(itemArr); | ||
nebulae.findAndModify({type: "supernova"}, [['name', 1]], | ||
{$set: {type:"Super Nova", "updated":true}}, | ||
{w:1, new:true}, function(err, doc) { | ||
console.log("After Modify: "); | ||
console.log(doc); | ||
db.close() | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,18 @@ | ||
var MongoClient = require('mongodb').MongoClient | ||
MongoClient.connect("mongodb://localhost/", function(err, db) { | ||
var myDB = db.db("astro"); | ||
myDB.collection("nebulae", function(err, nebulae) { | ||
nebulae.findOne({type: "Super Nova"}, function(err, item) { | ||
console.log("Before Save: "); | ||
console.log(item); | ||
item.info = "Some new info"; | ||
nebulae.save(item, {w:1}, function(err, results) { | ||
nebulae.findOne({_id: item._id}, function(err, savedItem) { | ||
console.log("After Save: "); | ||
console.log(savedItem); | ||
db.close(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,36 @@ | ||
var MongoClient = require('mongodb').MongoClient | ||
MongoClient.connect("mongodb://localhost/", function(err, db) { | ||
var myDB = db.db("astro"); | ||
myDB.collection("nebulae", function(err, nebulae) { | ||
nebulae.find({type: "diffuse"}, function(err, items) { | ||
items.toArray(function(err, itemArr) { | ||
console.log("Before Upsert: "); | ||
console.log(itemArr); | ||
nebulae.update({type: "diffuse"}, | ||
{$set: {ngc: "NGC 3372", name: "Carina", | ||
type: "diffuse", lcoation: "Carina"}}, | ||
{upsert: true, w:1, forceServerObjectId: false}, | ||
function(err, results) { | ||
nebulae.find({type: "diffuse"}, function(err, items) { | ||
items.toArray(function(err, itemArr) { | ||
console.log("After Upsert 1: "); | ||
console.log(itemArr); | ||
var itemID = itemArr[0]._id; | ||
nebulae.update({_id: itemID}, | ||
{$set: {ngc: "NGC 3372", name: "Carina", | ||
type: "Diffuse", location: "Carina"}}, | ||
{upsert: true, w:1}, function(err, results) { | ||
nebulae.findOne({_id: itemID}, function(err, item) { | ||
console.log("After Upsert 2: "); | ||
console.log(item); | ||
db.close(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|