欢迎投稿

今日深度:

node.js操作mongoDB大乐透追加倍投多少钱示例分享,

node.js操作mongoDB大乐透追加倍投多少钱示例分享,


连接大乐透追加倍投多少钱

复制代码 代码如下:
?var mongo=require("mongodb");
?var host="localhost";
?var port=mongo.Connection.DEFAULT_PORT;
?var server=new mongo.Server(host,port,{auto_reconnect:true});//创建大乐透追加倍投多少钱所在的服务器服务器
?var db=new mongo.Db("node-mongo-examples",server,{safe:true});//创建大乐透追加倍投多少钱对象
?db.open(function (err,db) {//连接大乐透追加倍投多少钱
???? if(err)
???????? throw err;
???? else{
???????? console.log("成功建立大乐透追加倍投多少钱连接");
???????? db.close();
???? }
?});
?db.on("close", function (err,db) {//关闭大乐透追加倍投多少钱
???? if(err) throw err;
???? else console.log("成功关闭大乐透追加倍投多少钱.");
?});

插入数据:

插入数据后,在控制台中输出数据文档的内容

复制代码 代码如下:
?var mongo=require("mongodb");
?var host="localhost";
?var port=mongo.Connection.DEFAULT_PORT;
?var server=new mongo.Server(host,port,{auto_reconnect:true});//创建大乐透追加倍投多少钱所在的服务器服务器
?var db=new mongo.Db("node-mongo-examples",server,{safe:true});//创建大乐透追加倍投多少钱对象
?db.open(function (err,db) {//连接大乐透追加倍投多少钱
???? if(err)
???????? throw err;
???? else{
???????? db.collection("users", function (err,collection) {
???????????? collection.insert({username:"盼盼",firstname:"李"}, function (err,docs) {
???????????????? console.log(docs);
???????????????? db.close();
???????????? });
???????? });???????
???? }
?});
?db.on("close", function (err,db) {//关闭大乐透追加倍投多少钱
???? if(err) throw err;
???? else console.log("成功关闭大乐透追加倍投多少钱.");
?});

关闭大乐透追加倍投多少钱db.close([forceClose],[callback]);

forceClose为true时,强制关闭该大乐透追加倍投多少钱,当大乐透追加倍投多少钱关闭后,不可再使用open开启大乐透追加倍投多少钱.

forceClose为false时,不强制关闭大乐透追加倍投多少钱,当大乐透追加倍投多少钱关闭后,可以再使用open打开.

当foreClose为true时:

复制代码 代码如下:
?var mongo=require("mongodb");
?var host="localhost";
?var port=mongo.Connection.DEFAULT_PORT;
?var server=new mongo.Server(host,port,{auto_reconnect:true});//创建大乐透追加倍投多少钱所在的服务器服务器
?var db=new mongo.Db("node-mongo-examples",server,{safe:true});//创建大乐透追加倍投多少钱对象
?db.open(function (err,db) {//连接大乐透追加倍投多少钱
???? if(err)
???????? throw err;
???? else{
???????? db.collection("users", function (err,collection) {
???????????? collection.insert({username:"盼盼",firstname:"李"}, function (err,docs) {
???????????????? console.log(docs);
???????????????? db.close(false);
???????????? });
???????? });
???? }
?});
?db.once("close", function (err,db) {//关闭大乐透追加倍投多少钱
???? if(err) throw err;
???? else {
???????? db.open(function (err,db) {
???????????? db.collection("users", function (err,collection) {
???????????????? collection.insert({username:"三",firstname:"张"}, function (err,docs) {
???????????????????? if(err) throw? err;
???????????????????? else{
???????????????????????? console.log(docs);
???????????????????????? db.close(true);
???????????????????? }
???????????????? })
???????????? });
???????? });
???? }
?});

//读取数据

复制代码 代码如下:
var mongo=require("mongodb");
var host="localhost";
var port=mongo.Connection.DEFAULT_PORT;
var server=mongo.Server(host,port,{auto_reconnect:true});
var db=new mongo.Db("node-mongo-examples",server,{safe:true});
db.open(function (err,db) {
??? db.collection("users", function (err,collection) {
??????? if(err) throw err;
??????? else{
??????????? collection.find({}).toArray(function(err,docs){
??????????????? if(err) throw? err;
??????????????? else{
??????????????????? console.log(docs);
??????????????????? db.close();
??????????????? }
??????????? });
??????? }
??? });
});

//带查询条件的搜索

复制代码 代码如下:
var mongo=require("mongodb");
var host="localhost";
var port=mongo.Connection.DEFAULT_PORT;
var server=mongo.Server(host,port,{auto_reconnect:true});
var db=new mongo.Db("node-mongo-examples",server,{safe:true});
db.open(function (err,db) {
??? db.collection("users", function (err,collection) {
??????? if(err) throw err;
??????? else{
??????????? collection.find({username:{$in:["延思","三"]}}).toArray(function(err,docs){
??????????????? if(err) throw? err;
??????????????? else{
??????????????????? console.log(docs);
??????????????????? db.close();
??????????????? }
??????????? });
??????? }
??? });
});

//插入一批数据,并且进行搜索type==food且price字段值小于10

复制代码 代码如下:
var mongo=require("mongodb");
var host="localhost";
var port=mongo.Connection.DEFAULT_PORT;
var server=mongo.Server(host,port,{auto_reconnect:true});
var db=new mongo.Db("node-mongo-examples",server,{safe:true});
var docs=[
??? {type:"food",price:11},
??? {type:"food",price:10},
??? {type:"food",price:9},
??? {type:"food",price:8},
??? {type:"book",price:9}
];
db.open(function (err,db) {
??? db.collection("goods", function (err,collection) {
??????? if(err) throw err;
??????? else{
??????????? collection.insert(docs, function (err,docs) {
??????????????? if(err) throw? err;
??????????????? else{
??????????????????? collection.find({type:"food",price:{$lt:10}}).toArray(
??????????????????????? function(err,docs){
??????????????????????????? if(err) throw err;
??????????????????????????? else{
??????????????????????????????? console.log(docs);
??????????????????????????????? db.close();
??????????????????????????? }
??????????????????????? }
??????????????????? );
??????????????? }
??????????? })
??????? }
??? });
});

查询中的或的表达:

复制代码 代码如下:
collection.find({$or:[
    {type:"food"},
    {price:{$lt:10}}
  ]})

有关node.js操作mongoDB大乐透追加倍投多少钱的讲解,今天就先到这里了,基本上常用的操作都有了示例,复杂些的,小伙伴们自由发挥吧,有机会我们再来继续讲解。

www.htsjk.Com true http://www.htsjk.com/MongoDB/33985.html NewsArticle node.js操作mongoDB大乐透追加倍投多少钱示例分享, 连接大乐透追加倍投多少钱 复制代码 代码如下: var mongo=require("mongodb"); var host="localhost"; var port=mongo.Connection.DEFAULT_PORT; var server=new mongo.Server(host,port,{auto_reconnect:true})...
评论暂时关闭