db.collection.createIndex(
{ partialFilterExpression: { fileName3: { $gt: 5 } } }
)
partialFilterExpression选项 | 定过滤条件的表达式 |
---|---|
partialFilterExpression | 等式表达式(即field: value或使用$eq 运算符) |
partialFilterExpression | $exists: true表达式 |
partialFilterExpression | $gt, $gte, $lt, $lte表达式 |
partialFilterExpression | $type表达式 |
partialFilterExpression | $and仅顶级运算符 |
db.restaurants.insert({
"_id" : ObjectId("5641f6a7522545bc535b5dc9"),
"address" : {
"building" : "1007",
"coord" : [
-73.856077,
40.848447
],
"street" : "Morris Park Ave",
"zipcode" : "10462"
},
"borough" : "Bronx",
"cuisine" : "Bakery",
"rating" : { "date" : ISODate("2014-03-03T00:00:00Z"),
"grade" : "A",
"score" : 2
},
"name" : "Morris Park Bake Shop",
"restaurant_id" : "30075445"
})
db.restaurants.createIndex(
{ borough: 1, cuisine: 1 },
{ partialFilterExpression: { 'rating.grade': { $eq: "A" } } }
)
db.restaurants.getIndexes()
db.restaurants.find( { borough: "Bronx", 'rating.grade': "A" } )
db.restaurants.find( { borough: "Bronx", 'rating.grade': "A" } ).explain()
db.restaurants.find( { borough: "Bronx", cuisine: "Bakery" } )
db.restaurants.find( { borough: "Bronx", cuisine: "Bakery" } ).explain()
db.users.insertMany( [
{ username: "david", age: 29 },
{ username: "amanda", age: 35 },
{ username: "rajiv", age: 57 }
] )
db.users.find()
db.users.createIndex(
{ username: 1 },
{ unique: true, partialFilterExpression: { age: { $gte: 21 } } }
)
db.users.insertMany([
{username:"david",age:27},
{username:"amanda",age: 25},
{username:"rajiv",age: 32}
])
db.users.insertMany( [
{ username: "david", age: 20 },
{ username: "amanda" },
{ username: "rajiv", age: null }
] )
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://wwwxz.blog.csdn.net/article/details/124574144
内容来源于网络,如有侵权,请联系作者删除!