find
This commit is contained in:
commit
152b6261a5
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.git
|
||||
node_modules
|
||||
*.log
|
87
package-lock.json
generated
Normal file
87
package-lock.json
generated
Normal file
@ -0,0 +1,87 @@
|
||||
{
|
||||
"name": "node-todo-api",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"bson": {
|
||||
"version": "0.5.7",
|
||||
"resolved": "https://registry.npmjs.org/bson/-/bson-0.5.7.tgz",
|
||||
"integrity": "sha1-DRH+CTbB/uAp4R9wY/XQqyQi6j4="
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
||||
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
|
||||
},
|
||||
"es6-promise": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.0.2.tgz",
|
||||
"integrity": "sha1-AQ1YWEI6XxGJeWZfRkhqlcbuK7Y="
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
|
||||
},
|
||||
"isarray": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
|
||||
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
|
||||
},
|
||||
"mongodb": {
|
||||
"version": "2.2.5",
|
||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.2.5.tgz",
|
||||
"integrity": "sha1-OucfiziiRjSk6+uvW7qYPs868r0=",
|
||||
"requires": {
|
||||
"es6-promise": "3.0.2",
|
||||
"mongodb-core": "2.0.7",
|
||||
"readable-stream": "1.0.31"
|
||||
}
|
||||
},
|
||||
"mongodb-core": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-2.0.7.tgz",
|
||||
"integrity": "sha1-3ma4uC6D+jPkRHJ/88yoDm9Vdbk=",
|
||||
"requires": {
|
||||
"bson": "0.5.7",
|
||||
"require_optional": "1.0.1"
|
||||
}
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "1.0.31",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.31.tgz",
|
||||
"integrity": "sha1-jyUC4LyeOw2huUUgqrtOJgPsr64=",
|
||||
"requires": {
|
||||
"core-util-is": "1.0.2",
|
||||
"inherits": "2.0.3",
|
||||
"isarray": "0.0.1",
|
||||
"string_decoder": "0.10.31"
|
||||
}
|
||||
},
|
||||
"require_optional": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz",
|
||||
"integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==",
|
||||
"requires": {
|
||||
"resolve-from": "2.0.0",
|
||||
"semver": "5.4.1"
|
||||
}
|
||||
},
|
||||
"resolve-from": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz",
|
||||
"integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c="
|
||||
},
|
||||
"semver": {
|
||||
"version": "5.4.1",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.4.1.tgz",
|
||||
"integrity": "sha512-WfG/X9+oATh81XtllIo/I8gOiY9EXRdv1cQdyykeXK17YcUW3EXUAi2To4pcH6nZtJPr7ZOpM5OMyWJZm+8Rsg=="
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "0.10.31",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
|
||||
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
|
||||
}
|
||||
}
|
||||
}
|
15
package.json
Normal file
15
package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "node-todo-api",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"mongodb": "^2.2.5"
|
||||
}
|
||||
}
|
35
playground/mongodb-connect.js
Normal file
35
playground/mongodb-connect.js
Normal file
@ -0,0 +1,35 @@
|
||||
// const MongoClient = require('mongodb').MongoClient;
|
||||
const {MongoClient, ObjectID} = require('mongodb');
|
||||
|
||||
|
||||
var mongoUrl = 'mongodb://127.0.0.1:27017/TodoApp';
|
||||
|
||||
MongoClient.connect(mongoUrl, (err, db) => {
|
||||
if (err) {
|
||||
return console.log('Unable to connect to MongoDB Server', err);
|
||||
}
|
||||
// db.collection('Todos').insertOne({
|
||||
// text: 'Something to do',
|
||||
// completed: false
|
||||
// }, (err, result) => {
|
||||
// if (err) {
|
||||
// return console.log('Unable to insert todo', err);
|
||||
// }
|
||||
// console.log(JSON.stringify(result.ops, undefined, 2));
|
||||
// })
|
||||
|
||||
// db.collection('Users').insertOne({
|
||||
// name: "Tyrel",
|
||||
// age: 29,
|
||||
// location: "Boston"
|
||||
// }, (err, result) => {
|
||||
// if (err) {
|
||||
// return console.log('Unable to insert user', err);
|
||||
// }
|
||||
// console.log(JSON.stringify(result.ops, undefined, 2));
|
||||
// console.log(result.ops[0]._id.getTimestamp());
|
||||
// })
|
||||
|
||||
|
||||
db.close();
|
||||
})
|
26
playground/mongodb-find.js
Normal file
26
playground/mongodb-find.js
Normal file
@ -0,0 +1,26 @@
|
||||
// const MongoClient = require('mongodb').MongoClient;
|
||||
const {MongoClient, ObjectID} = require('mongodb');
|
||||
|
||||
|
||||
var mongoUrl = 'mongodb://127.0.0.1:27017/TodoApp';
|
||||
|
||||
MongoClient.connect(mongoUrl, (err, db) => {
|
||||
if (err) {
|
||||
return console.log('Unable to connect to MongoDB Server', err);
|
||||
}
|
||||
// db.collection('Todos').find().toArray().then((docs) => {
|
||||
// console.log("Todos");
|
||||
// console.log(JSON.stringify(docs, null, 2));
|
||||
//
|
||||
// }, (err) => {
|
||||
// console.log("Unable to fetch todos", err);
|
||||
// })
|
||||
|
||||
db.collection('Users').find({name: 'Tyrel'}).toArray().then((docs) => {
|
||||
console.log(JSON.stringify(docs, null, 2));
|
||||
}, (err) => {
|
||||
console.log("Unable to fetch todos", err);
|
||||
})
|
||||
|
||||
// db.close();
|
||||
})
|
Loading…
Reference in New Issue
Block a user