umutbozkurt/django-rest-framework-mongoengine

mongoengine can operate db like this ? limit is invalid

358235737 opened this issue · 10 comments

Alert.objects(Q(status='0') & Q(subsys=subsys) & ( Q(timestamp__gte=self.start_time) & Q(timestamp__lte=self.end_time))).limit(num).update(status="2")

limit is invalid

Alert.objects(Q(status='0') & Q(subsys=subsys) & ( Q(timestamp__gte=self.start_time) & Q(timestamp__lte=self.end_time))).limit(num)
limit is valid

how to operate query ...limit...update?

You can use slice notation and you probably don't need Qs.

Something like:

Alert.objects(status='0', subsys=subsys, timestamp__get=self.start_time, timestamp__lte=self.end_time)[:num].updated(status="2")

this :
Alert.objects(status='0', subsys=subsys, timestamp__get=self.start_time, timestamp__lte=self.end_time)[:num].updated(status="2")

I had try,but not valid ,it is also updated all
[:num] is invalid in this way

re = Alert.objects(Q(status='0') & Q(subsys=subsys) & (
Q(timestamp__gte=self.start_time) & Q(timestamp__lte=self.end_time)))[:num]
logger.info("re.count() :%s" %re.count())

that [:num] or limit(num) are not invalid
why ?
that query result are all?
why ?

and with this code :
re = Alert.objects[:2]
also return all ?

hmarr/mongoengine#166
something else ?

@358235737

Sorry, I've never run into issues with slicing. Maybe just try re-writing this as a for loop, if nothing else helps. May I also ask you to use syntax formatting with triple backticks.

OK, if you run this issues and resolved ,please tell me ,thank you ~~!

@358235737 I think this issue is more related to the pure mongoengine, so you're more likely to get some help there =)