Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reformatted QuickTour example

  • Loading branch information...
commit 2eed22e1ab63c4c2906f3c5e850eb0e888bed095 1 parent 329945e
@sergi authored
Showing with 21 additions and 50 deletions.
  1. +21 −50 tests/examples/QuickTour.js
View
71 tests/examples/QuickTour.js
@@ -1,85 +1,58 @@
var MongoDB = require("mongodb");
-var $ = require("util");
+var db = new MongoDB.Mongo( "localhost" ).getDB( "mydb" );
-var QuickTour = function() {
- var m = new MongoDB.Mongo();
- var db = m.getDB("mydb");
+(function() {
+ (db.getCollectionNames())
+ .forEach(function(el) { print(el); });
- var colls = db.getCollectionNames();
-
- colls.forEach(function(el) { print(el); });
print(" --- ");
- var coll = db.getCollection("testCollection");
+ var coll = db.getCollection("test1");
coll.drop();
var doc = {
name: "MongoDB",
type: "database",
- count: 1
+ count: 1,
+ info: {
+ x: 203,
+ y: 102
+ }
};
- var info = {
- x: 203,
- y: 102
- }
-
- doc.info = info;
coll.insert(doc)
- /*
- * get it (since it's the only one in there since we dropped the rest earlier on)
- */
- myDoc = coll.findOne();
-
- print(myDoc);
-
- /*
- * now, lets add lots of little documents to the collection so we can explore queries and cursors
- */
-
+ //get it (since it's the only one in there since we dropped the rest earlier on)
+ print(coll.findOne());
print(" --- ");
- for (var i=0; i < 100; i++) {
- coll.insert({"i": i});
- }
+ //now, lets add lots of little documents to the collection so we can explore queries and cursors
+ for (var i = 0; i < 100; i++)
+ coll.insert({ "i": i });
print(coll.getCount());
-
- /*
- * lets get all the documents in the collection and print them out
- */
-
print(" --- ");
+ //lets get all the documents in the collection and print them out
var cur = coll.find();
- while(cur.hasNext()) {
+ while (cur.hasNext())
print(cur.next());
- }
-
- /*
- * now use a query to get 1 document out
- */
print(" --- ");
- var query = {i: 71};
-
+ // now use a query to get 1 document out
+ var query = { i: 71 };
cur = coll.find(query);
while(cur.hasNext())
print(cur.next());
- /*
- * now use a query to get a larger set
- */
-
print(" --- ");
+ // now use a query to get a larger set
query = { "i": {"$gt": 50} }; // i.e. find all where i > 50
-
cur = coll.find(query);
while(cur.hasNext())
@@ -88,10 +61,8 @@ var QuickTour = function() {
print(" --- ");
query = { "i": { "$gt": 20, "$lte": 30} }; // i.e. 20 < i <= 30
-
cur = coll.find(query);
while(cur.hasNext())
print(cur.next());
-}
-QuickTour();
+})();
Please sign in to comment.
Something went wrong with that request. Please try again.