MongoDB stores data in flexible, JSON-like documents, meaning fields can vary from document to document and data structure can be changed over time.
- MongoDB Manual;
- About mongodb @ stackoverflow;
-
docs
MongoDB Examples - Structuring Document Data
- Stack Overflow;
- MongoDB Architecture Guide;
命令
- 在 linux 下將
/usr/local/mongodb/bin/
加到PATH
段化。 -
mongo
即可進入 - 示例如下嘁捷,詳解見后。
> help
> db.help()
> db.mycoll.help()
> db.d_321100.find( {"VALUE": new BinData(0,"MzIxMTkxMjEwMDAxNDk=") } ).sort({TM:-1}).limit(1)
> db.d_321100.find( {SN: { $regex: /-32119121000149-/ }, TYPE: 101 } ).sort({TM:-1}).limit(1).pretty()
> db.d_321100.find( {SN: { $regex: /-32119121000149-/ }, TYPE: {$in:[101,102]} } ).sort({TM:-1}).limit(1)
> db.d_321100.find( {SN: { $regex: /-32119121000149-/ }, TYPE: {$in:[101,102]} } ).count()
庫 libmongoc
- A Cross Platform MongoDB Client Library for C. 站內(nèi)搜索做的好显熏,可以很方便查看 數(shù)據(jù)結(jié)構(gòu)和函數(shù)說明雄嚣。
help
-
> help
> db.help()
-
> db.mycoll.help()
指定的 mycoll 集合的方法
-
db.d_320100.getIndexes
查當(dāng)前索引
示例
- 以 PAIBO 標準為示例。
- 指定場所是否有場所心跳數(shù)據(jù)喘蟆?
由于場所心跳UDP數(shù)據(jù)包的內(nèi)容就是場所編碼
缓升,因此直接搜索所存儲的二進制數(shù)據(jù)即可: - MongoDB Shell: find by BinData。
- 場所編碼 32119121000149(base64值:MzIxMTkxMjEwMDAxNDk=)最近一條場所心跳數(shù)據(jù):
db.d_321100_XXXXXXXXX.find( {"VALUE": new BinData(0,"MzIxMTkxMjEwMDAxNDk=") } ).sort({TM:-1}).limit(1)
{ "_id" : ObjectId("5c46c6cda1b9402f388908ad"),
"SN" : "321100---0-7621138-SITESTATUS-0",
"TM" : NumberLong("1548142285103"),
"UTM" : NumberLong("1548142285518"),
"FLAG" : NumberLong(200),
"TYPE" : 105,
"VALUE" : BinData(0,"MzIxMTkxMjEwMDAxNDk=")
}
- 場所編碼 32119121000149(位于 SN 中)蕴轨,終端上下線(TYPE 101)的最近一條格式化數(shù)據(jù)
> db.d_321100_XXXXXXXXX.find( {SN: { $regex: /-32119121000149-/ }, TYPE: 101 } ).sort({TM:-1}).limit(1).pretty()
{
"_id" : ObjectId("5c46f3eca1b9402f38b06e8f"),
"SN" : "321100-32119121000149-XXXXXXXXX749D79E98850-1548152023-7876037-WA_SOURCE_FJ_0001",
"TM" : NumberLong("1548153836614"),
"UTM" : NumberLong("1548153836707"),
"FLAG" : NumberLong(200),
"TYPE" : 101,
"VALUE" : BinData(0,"Vjk2dDVyd1VRdmp2V0VNcjVRPT0=")
}
注:示例中的 VALUE 字段值經(jīng)過裁剪港谊。即使未經(jīng)裁剪,也是加密過的數(shù)據(jù)橙弱。
- 場所編碼 32119121000149(位于 SN 中)歧寺,終端上下線(TYPE 101)或者虛擬身份(102)的最近一條數(shù)據(jù):
> db.d_321100_XXXXXXXXX.find( {SN: { $regex: /-32119121000149-/ }, TYPE: {$in:[101,102]} } ).sort({TM:-1}).limit(1)
- 場所編碼 32119121000149(位于 SN 中),終端上下線(TYPE 101)或者虛擬身份(102)一共有多少條數(shù)據(jù):
> db.d_321100_XXXXXXXXX.find( {SN: { $regex: /-32119121000149-/ }, TYPE: {$in:[101,102]} } ).count()
1580
正則搜索
- Selects documents where values match a specified regular expression.
- Provides regular expression capabilities for pattern matching strings in queries. MongoDB uses Perl compatible regular expressions (i.e. “PCRE” ) version 8.41 with UTF-8 support.
文本搜索
-
Text Search
Performs text search. - MongoDB supports query operations that perform a text search of string content. To perform text search, MongoDB uses a text index and the
$text
operator. - A collection can only have one text search index, but that index can cover multiple fields.