mongodb - Updating array with push and slice -


I have just started playing with Mangoodi and there are some questions about how I update my documents in the database I am I insert two documents in my DB with

  db.userscores.insert ({name: 'John do', email: 'john.doe@mail.com', level :) I [[Level: 1, Haakors: [90, 40, 25], Aquimant: ['Flag capture', 'It can only be one', 'apple collector', 'level complete']}, {level : 2, Haakors: [30, 25], achivements: ['full level']}, {level 3, helicopters: [], achivements: []}]}); Db.userscores.insert ({Name: 'Jane Doe', email: 'jane.doe@mail.com', Level: [[Level: 1, Helicopters: [150, 90], Achievements: ['Master of the Universe' , 'Capture the flag', 'this can only be one', 'apple collector', 'level full']}]});   

I check that my inclusion has worked with the find () command and it looks okay.

  db.userscores.find (). beautiful (); {"" "Email"): "john.doe@mail.com", "level": [{"level": 1, "helocors"): "{_id}": ObjectID ("5358b47ab826096525d0ec98"), " Name ":" John Doe "," Level ": 2," Helicopter ": [90, 40, 25]," Aquinites ": [" Capture the Flag "," It Can Be Only One "," Apple Collector " , "Level": {"Level": {"Level": 3, "Hookurus": [], "Equipment": []}] {"_id": ObjectId ("", "Name": " "[[" Level ": 1," hookus ": [150, 90]," Achievements ": [" Master of the Universe ":" Jane Doe "," Email ":" jane.doe@mail.com "," Level " , "Capture the flag", "it can only be one", "apple collect R "," level full "]}]}   

How can I update my users? Let's say I have a user on John Doe at Level 1 How do I insert her quick 75 and still her array is sorted? Can I limit the number of my rights so that only 3 elements in the array are included? I have tried.

  db.userscores.aggregate (// Initial document {Match: {name: 'John Doe}}}, // expand the levels in a section of documents {$ opening:' $ level '}, Filters 'Level 1' score {$ match: {'levels.level': 1}}, // add score 75 {$ push with cap / cap of 3 elements: {'levels.hiscore': {$ each [75] ], $ Piece: -3}}});   

But it is used to working, the error I get is "Syntax Error: Unexpected Tokens [".

And also, how do I get 10 highest scores from all users, for example on Level 1? Is my document plan okay or can I use a better plan for my game at different levels to operate users? Is there a downside on queering or performance using the above scheme?

You can add scores with this statement: {"Level.level": 1}, { "$ Push": {"levels. $. Haeccores"

  db.userscores.update ({"name": "John doe": 75}})   

This will sort the ARM not because it is only supported if your array element is documented.

In Mongodi 2.6 you can also use the sorting for non-document array:

  db.userscores.update ({"name": "John doe" , "level.level": 1}, {"$ push": {"level. $ .harkcores": {$ each: [75], $ sort: -1, $ piece: 3}}})    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -