Problem with sort in default code template

Ivica Hrg shared this problem 4 years ago
Solved

Inside "default code template" I've added ".sort({_id:-1})" but any time I open some colelction, that sorting part is commented and I must uncomment it


Settings

f8d0bc465b41f50fea230a424c2a29dd


First openening of some collection

327276734ccfce97fdd47ec3f1bb0e18

Replies (21)

photo
1

If the collection "testtesttest1" has no "_id" index, the ".sort({_id:1})" line will be commented.

Could you please show the script result "db.testtesttest1.getIndexes();"?

photo
1

{
	"ns" : "testdb.testtesttest1",
	"v" : 1,
	"key" : {
		"_id" : 1
	},
	"name" : "_id_"
}

photo
1

And i am using the latest version

/6be130d8b1c21d14bb07c874efe1c00d

photo
1

Thanks for your feedback.

Could you please run the script "db.getCollection("testtesttest1").stats().indexSizes" in the NoSQLBooster and show the result?

photo
1

{
	"_id_" : 36864
}

photo
1

We have worked out a test build to resolve the issue, please download and give it a try.

mac os: https://s3.mongobooster.com/download/releasesv5/nosqlbooster4mongo-5.1.6-beta.1.dmg

photo
1

I tried, not solving my problem.

Also i do not think its a problem related to index, cause when i remove the projection in template:

db.%%collection%%.find({$1})
   .sort({_id:-1})
   .limit(%%limit%%)
i still get this, it just dont apply the template config. And still the problem only occurs to specific connections.

db.testtesttest1.find({})
    .projection({})
    //.sort({_id:-1})
    .limit(100)

photo
1

Thank you for your fast feedback.

The reason we check the index is that some collection(e.g. local.oplog.rs) may not have an _id index, which causes the error to open the collection. Your collection has _id index, I don't quite understand why the sort is commented out.

Because it cannot be reproduced locally, tracking problems like this are indeed less efficient. Could you please give me a screenshot including the indexes node like the following picture?

/e6d3f75c03f10a7a23e0c8690839e65c

photo
1

And, If the indexes node has "_id_" child node, please focus to connection tree (left pane), press "CTRL+ALT+SHIFT+F7" to toggle developer toolbar and open the test collection, are there any logged info?

photo
1

/ace04c2a70abfa8e23a8e039844536e2

/2eea6c52b05ff33d27a9f36f3eb4ca97

photo
1

It looks strange, could you give me a full screenshot?

photo
1

Sorry i cant, it will contain privacy info.

photo
1

The problem of not being able to reproduce locally is difficult to locate, I will set the problem to not reproduce, and if there is a complete reproduction step, I will come back.

photo
1

db.%%collection%%.find({$1})
   .sort({_id:-1})

also got the same problem, my template is different, but I still getting default one with commented sort. happening to a specific connection and not related to collection

photo
1

Thank you for your feedback.

Does your collection have an _id index? If there is no _id index, NoSQLBooster automatically comments out the sorted part when the collection is opened. And, collection "oplog.rs" has no _id index.

Could you please run the script "db.getCollection("your_collection").stats().indexSizes" in the NoSQLBooster and show the result?

photo
1

Yes it does

{
	"_id_" : 356352,
	"activatedAt_-1" : 159744,
	"createdAt_-1" : 253952,
	"canceledAt_-1" : 69632,
	"active_1" : 114688,
	"name_1" : 368640
}

photo
1

for example our staging db with the same collection but less data working well, but in production we just getting default commented template

photo
1

And, If the indexes node has "_id_" child node, please focus to connection tree (left pane), press "CTRL+ALT+SHIFT+F7" to toggle developer toolbar and open the test collection, are there any logged info? And, please provide the following information.

  • NoSQLBooster Version
  • Operating System (Windows/Mac/Ubuntu):
  • MongoDB Version
  • Sample JSON Data

photo
1

/508d61f8dc6188a75165fa29b87d295e

photo
1

/639d7e7be28396bc64ebd1f251f8bb9c

Probably i found a problem, if i'll double click on expanded collection it work as expected, but if i'll do the same to not expanded one it will be default template with commented sort. But after i expand the same collection it working

photo
1

Solution from Vlad also works for me... but anyway, my opinion is that if I create anything in template, it should be exactly the same in editor when I open it.... so if I create temaplte with some faulty index, it's my problem

photo
photo
1

Some commonly used collection, such as "oplog.rs", do not have an _id_ index, but the data set is very large. If you do not comment out the sorting part, it will cause the data set to be opened very slowly, so we have to do so much more.

photo
1

Ok, but the problem itself is not about commenting it... You not using my template at all instead of comment sort

photo
1

I still think you should leave that choice to user of app.... For example if I work with oplog I must choose will I comment the sort or not... And if I dont work with oplog ( and I really never use it ) I must have an option for it to work as I like it...

Also you have a great option not to run query when collection is opened, so I have to run it manually ( which I use ) and in those cases user can choose how app will behave...

And how it is now it looks like I can choose app behaviour. but I cant... Now I've tried to comment everything inside template, and still when I open collection, only sort is commentd, and everything else is not... so it looks like that "Default Code Template" is useless - because whatever I set inside, it doesn't work

Here is an example

ff8cb3b4d58f370d607fccfc63cd3b4d

photo
1

Thanks.

Yes, there are implementation issues here, it’s hard to justify the sorting part of your custom script. It might be better to do special processing only for some common unindexed collections (e.g. oplog.rs).

photo
1

We have worked out a new test build to resolve this issue, please download and give it a try. In this build, we limit the scope of commenting sorting line to a small number of the special collections (e.g. oplog.rs , system.profiler ...., capped and no _id_ index)

Mac OS: https://s3.mongobooster.com/download/releasesv5/nosqlbooster4mongo-5.1.8-beta.1.dmg

Windows: https://s3.mongobooster.com/download/releasesv5/nosqlbooster4mongo-5.1.8-beta.1.exe

Linux AppImage: https://nosqlbooster.com/s3/download/releasesv5/nosqlbooster4mongo-5.1.8-beta.1.AppImage

photo
1

Unfortunately it's not working for me. OS is "Win 10 PRO", MongoDB version is "4.0.5"

Here is screenshot, and on it you can see that I have uncommented "sort" and commented "limit", but both of those changes are not applied.

18259e44cf91d17a140ac7b6d9551c8e

photo
1

Also not working for me, nothing changed

photo
2

Thank you for your feedback.

We did make a mistake, and the option "Menu->Options->Options That May Affect Performance->Show Database/Collection Stats Tooltip" causes the default code template selection to go wrong. Please turn off this option or give the following new test build a try.

Mac OS: https://s3.mongobooster.com/download/releasesv5/nosqlbooster4mongo-5.1.8-beta.2.dmg


Windows: https://s3.mongobooster.com/download/releasesv5/nosqlbooster4mongo-5.1.8-beta.2.exe


Linux AppImage: https://nosqlbooster.com/s3/download/releasesv5/nosqlbooster4mongo-5.1.8-beta.2.AppImage

photo
1

I've tested new build, and now it works fine, Thanks a lot for fast fix.

photo
1

Working for me, thanks! Waiting for release.

photo
1

Resolved in 5.1.8

Leave a Comment
 
Attach a file