balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.85k stars 1.95k forks source link

mongo adapter $exists #4481

Open bhaveshbheda opened 6 years ago

bhaveshbheda commented 6 years ago

Sails version:1.0 Node version:8.10 NPM version:3.5.2 DB adapter name: sails-mongo DB adapter version: 1.0 Operating system: linux after upgrading sails 1.0 from 0.12 in mongo adapter there is no any alternative for "$exists", array notation like "user.$.name" or "user.1" which is working in sails 0.12 and mongo adopter of 0.12 . . . .


sailsbot commented 6 years ago

Hi @bhaveshbheda! It looks like you missed a step or two when you created your issue. Please edit your comment (use the pencil icon at the top-right corner of the comment box) and fix the following:

As soon as those items are rectified, post a new comment (e.g. “Ok, fixed!”) below and we'll take a look. Thanks!

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

bhaveshbheda commented 6 years ago

please give me suggestion for it

sailsbot commented 6 years ago

Sorry to be a hassle, but it looks like your issue is still missing some required info. Please double-check your initial comment and try again.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

streleck commented 6 years ago

@bhaveshbheda Could you use Object.find({key: {'!=': null}})?

OnbitShashan commented 4 years ago

@streleck this does not works. I need the opposite of this. I have something like parentId: { $exists: false } . Now I'm upgrading into sails 1.x and stuck here. I need to fetch all the records that does not contain parentId .

johnabrams7 commented 4 years ago

@OnbitShashan we just released sails-mongo 1.1.0 yesterday - can you try this query in the new version of the adapter? This update expands overall functionality, compatibility, and official support for mongo 3.6 (thorough testing / official support for mongo 4.x still being developed but should be relatively compatible).

OnbitShashan commented 4 years ago

@johnabrams7 I have tried this with 1.1.0. Still did not work. Find the error log below,

Error => UsageError: Invalid criteria. Refer to the docs for up-to-date info on query language syntax:
https://sailsjs.com/docs/concepts/models-and-orm/query-language 
Details: Could not use the provided `where` clause.  Could not filter by `parentId`: Unrecognized modifier (`$exists`) within provided constraint for `parentId`. [?] See https://sailsjs.com/support for help. 
error: Sending 500 ("Server Error") response:  
message=Invalid criteria. 
Refer to the docs for up-to-date info on query language syntax: https://sailsjs.com/docs/concepts/models-and-orm/query-language 
Details: 
Could not use the provided `where` clause.  Could not filter by `parentId`: Unrecognized modifier (`exists`) within provided constraint for `parentId`  [?] See https://sailsjs.com/support for help., stack=UsageError: Invalid criteria.  
Refer to the docs for up-to-date info on query language syntax: 
https://sailsjs.com/docs/concepts/models-and-orm/query-language  Details:  
Could not use the provided `where` clause.  Could not filter by `parentId`: Unrecognized modifier (`exists`) within provided constraint for `parentId`.  [?] See https://sailsjs.com/support for help.  

Please note that I tried with "$exists" and "exists"

johnabrams7 commented 4 years ago

@OnbitShashan Ah! In Sails 1.0/Waterline 0.13, we actually have stricter built-in validations, which is why this doesn’t work anymore. See .manager and .native() queries.

OnbitShashan commented 4 years ago

@johnabrams7 yeah writing code in native works. Sorry for the late reply