MongoDB allowDiskUse not working..

后端 未结 3 1197
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-05 14:55

Experts.

I\'m new to MongoDB, but know enough to get my self in trouble.. case in point:

db.test.aggregate(
[
    {$group: {_id: {email: \"$email\", ge         


        
相关标签:
3条回答
  • 2021-02-05 15:20

    If you are working with m10 or later version of MongoDB Atlas, below is the fix for {allowDiskUse: true}; If you are accessing data from application via mongoose then, it should be syntax as function. For example:

    MongoDb Query:

    db.collection.user.aggregate([], {allowDiskUse: true})
    

    With Mongoose:

    User.aggregate([]).allowDiskUse(true);
    

    This will resolve error from application :)

    0 讨论(0)
  • 2021-02-05 15:26

    Try writing like this,

    db.stocks.aggregate([
                         { $project : { cusip: 1, date: 1, price: 1, _id: 0 } },
                         { $sort : { cusip : 1, date: 1 } }
                        ],
                         {
                           allowDiskUse: true
                         }
                        ); 
    

    And One more thing,
    Your error about maximum document size is inherent to Mongo. Mongo can never return a document (or array thereof) larger than 16 megabytes. I can't tell you why because you didn't mention anything about data size, but it probably means that the document you're building as an end result is too large. Try decreasing the $limit parameter, maybe? Start by setting it to 1, run a test, then increase it and look at how big the result gets when you do that

    0 讨论(0)
  • 2021-02-05 15:27

    Please use aggregate query in run command,it will allow to use allowDiskUse tag.

    db.runCommand(
       { aggregate: "test",
         pipeline: [
                    {$group: {_id: {email: "$email", gender: "$gender"}, cnt: {$sum: 1}}}, 
                    {$group: {_id: "$_id.email", cnt: {$sum: 1}}}, 
                    {$match: {cnt: 2}}
                   ],
         allowDiskUse: true
       }
    )
    
    0 讨论(0)
提交回复
热议问题