Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$exists array [] (quantum mechanics of data base) #581

Open
impfromliga opened this issue Dec 9, 2018 · 2 comments
Open

$exists array [] (quantum mechanics of data base) #581

impfromliga opened this issue Dec 9, 2018 · 2 comments

Comments

@impfromliga
Copy link

impfromliga commented Dec 9, 2018

//strange result with $exists on Arrays:

db.find({},(err,all)=>{
	db.find({arr:{$exists:true}},(err,exists)=>{
		db.find({arr:{$exists:false}},(err,empty)=>{
			console.log('done count exists', all.length, '=', exists.length + empty.length);
			//done count exists 416 = 305
			//wtf?
		})
	})
})
@impfromliga
Copy link
Author

Perhaps some where in the library the fact of property $exists check like if(property) or etc.
Or i'm bad understand the rule that $exists "return true".
In case of array follows that [] not $exists, and not not $exist!
such a quantum mechanics of data base...

@impfromliga impfromliga changed the title $exists array [] $exists array [] (quantum mechanics of data base) Dec 9, 2018
@JamesMGreene
Copy link
Contributor

@impfromliga Can you confirm that your data set also contained 111 records with an empty array value ([]) for the arr property?

I added some quick checks to various array values in the tests to try to reproduce this. It appears that an empty array fails to match on both $exists: true and $exists: false.

model.match({ a: [5, 6] }, { a: { $exists: true } }).should.equal(true);

model.match({ a: [5] }, { a: { $exists: true } }).should.equal(true);
model.match({ a: [5] }, { b: { $exists: false } }).should.equal(true);

model.match({ a: [0] }, { a: { $exists: true } }).should.equal(true);
model.match({ a: [null] }, { a: { $exists: true } }).should.equal(true);

model.match({ a: [] }, { a: { $exists: false } }).should.equal(false);

model.match({ a: [] }, { a: { $exists: true } }).should.equal(true); // UNEXPECTED FAIL

JamesMGreene added a commit to JamesMGreene/nestdb that referenced this issue Mar 10, 2019
JamesMGreene added a commit to JamesMGreene/nestdb that referenced this issue Mar 10, 2019
JamesMGreene added a commit to JamesMGreene/nestdb that referenced this issue Mar 10, 2019
JamesMGreene added a commit to JamesMGreene/nestdb that referenced this issue Mar 10, 2019
JamesMGreene added a commit to JamesMGreene/nedb that referenced this issue Mar 10, 2019
JamesMGreene added a commit to JamesMGreene/nedb that referenced this issue Mar 10, 2019
JamesMGreene added a commit to JamesMGreene/nedb that referenced this issue Mar 11, 2019
JamesMGreene added a commit to JamesMGreene/nestdb that referenced this issue Mar 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants