Reputation: 8301
I want create and index to specific values to the fields producto
and color
Something like:
db.ensayo.createIndex({producto:1:"myvalue",color:1:"myvalue2"});
It is posible?
Upvotes: 0
Views: 1424
Reputation: 46
Yes, it is possible now. I think you can use this solution. You can set multiple indexes with their specific values.
db.ensayo.createIndex(
{
"producto":1,
"color":1
},
{
"unique" :true,
"partialFilterExpression" : {
"producto":{
"$eq": "myvalue"},
"color": { "$eq": "myvalue2"}
}
}
);
Source: mongodb docs partialFilterExpression
Upvotes: 3
Reputation: 222939
No, it is not possible. Also it looks really strange to do this. This index will perfectly answer your query:
db.ensayo.createIndex({
producto:1,
color:1
})
Upvotes: 1