Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

performance - Using $all operator when using Mongodb

I need to design a mongo collection in this structure:

{
   _id: "601af6f8ab9f370c2f7c0c38",
   users: [1111, 2222, 3333],
   chat_id: "chat_1"
},
{
   _id: "601af6f8ab9f370c2f7c0c40",
   users: [1111, 2222],
   chat_id: "chat_2"
},
{
   _id: "601af6f8ab9f370c2f7c0c50",
   users: [2222, 3333],
   chat_id: "chat_3"
},
{
   _id: "601af6f8ab9f370c2f7c0c50",
   users: [2222, 4444],
   chat_id: "chat_4"
}

And i want to perform this query:

db.getCollection('users_collection').find({users: {$all : [2222, 3333]}})

Which will result:
{
   _id: "601af6f8ab9f370c2f7c0c38",
   users: [1111, 2222, 3333],
   chat_id: "chat_1"
},
{
   _id: "601af6f8ab9f370c2f7c0c50",
   users: [2222, 3333],
   chat_id: "chat_3"
}

One of my application assumption is that the users list for each document is small
(most of the lists will be in length 2, and around 10% will be in 3-10 length)
So, the users list can be considered as small sized for all documents.

For the query i have specified above, i need to index users field .

Does anyone had an experience with indexing a list field in mongo and perform
queries with $all operator which supported good execution time on high scale?
(I am estimating around 1B documents in that collection)

Thanks !

question from:https://stackoverflow.com/questions/66060942/using-all-operator-when-using-mongodb

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...