MongoDB_類型操作符

'use strict';

// connect MongoDB
var mongodb = require("mongodb");
var server = new mongodb.Server("127.0.0.1", 27017, {auto_reconnect:true});
var client = new mongodb.Db("testDB", server, {w:1});

client.open(function(err, db){
    if (err)
    {
        throw err;
    }
    else
    {
        db.collection("testTable", {safe:true}, function(err, collection){
            if (err)
            {
                throw err;
            }
            else
            {
                // 全部查找
                collection.find().toArray(function(err, result){
                    //JsonLog(result);
                });

                // 類型操作符 $type查找
                collection.find({age:{$type:16}}).toArray(function(err, result){
                    JsonLog(result);
                });
            }
        });
    }
});

/*
Double	                1
String	                2
Object	                3
Array	                4
Binary data	            5
Undefined	            6	已廢棄。
Object id	            7
Boolean	                8
Date	                9
Null	                10
Regular Expression	    11
JavaScript	            13
Symbol	                14
JavaScript (with scope)	15
32-bit integer	        16
Timestamp	            17
64-bit integer	        18
Min key	                255	Query with -1.
Max key	                127
*/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章