1. 导入数据
[hadoop@hadoop1 bin]$ mongod -f mongodb.conf &
[1] 3702
[hadoop@hadoop1 bin]$ mongoimport --db catalog --collection books --type json --drop --file /opt/module/mongodb/tmp/catalog.books.json
2020-09-24T19:34:10.398+0800 connected to: localhost
2020-09-24T19:34:10.399+0800 dropping: catalog.books
2020-09-24T19:34:10.448+0800 imported 431 documents
> use catalog
switched to db catalog
> show collections
books
> db.books.find().count()
431
> db.books.findOne()
- 定义文本索引
//weights 使用到了weights权重,给对于的字段设置权重,那么查询到该字段后的结果分值将乘以对应的权重,提示分数值。
> db.books.createIndex( {title: 'text',shortDescription: 'text',longDescription: 'text', authors: 'text',categories: 'text'},{weights:{title: 10,shortDescription: 1,longDescription:1,authors: 1,categories: 5}});
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
> db.books.stats()
{
"ns" : "catalog.books",
"size" : 517474,
"count" : 431,
"avgObjSize" : 1200,
"storageSize" : 311296,
"capped" : false,
"wiredTiger" : {
"metadata" : {
"formatVersion" : 1
},
"creationString" : "access_pattern_hint=none,allocation_size=4KB,app_metadata=(formatVersion=1),assert=(commit_timestamp=none,read_timestamp=none),block_allocation=best,block_compressor=snappy,cache_resident=false,checksum=on,colgroups=,collator=,columns=,dictionary=0,encryption=(keyid=,name=),exclusive=false,extractor=,format=btree,huffman_key=,huffman_value=,ignore_in_memory_cache_size=false,immutable=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=q,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=64MB,log=(enabled=true),lsm=(auto_throttle=true,bloom=true,bloom_bit_count=16,bloom_config=,bloom_hash_count=8,bloom_oldest=false,chunk_count_limit=0,chunk_max=5GB,chunk_size=10MB,merge_custom=(prefix=,start_generation=0,suffix=),merge_max=15,merge_min=0),memory_page_max=10m,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,source=,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,type=file,value_format=u",
"type" : "file",
"uri" : "statistics:table:collection-0-6135922527786654092",
"LSM" : {
"bloom filter false positives" : 0,
"bloom filter hits" : 0,
"bloom filter misses" : 0,