Comments (5)
Currently, you can put objects in arrays in NeDB. You can then query the array field as usual (that is, query it like a normal field and if any element of the array matches there is a match). The cool thing is that NeDB does deep-equality matching for basic queries on objects, so you can write queries like this:
var db = new Datastore({ inMemoryOnly: true });
db.insert({ a: 5, b: [ 'yo', { bloup: 'blip' }, 7 ] }, function (err, newDoc) {
// First element of the array, a native type string)
db.findOne({ b: 'yo' }, function (err, doc) {
console.log(doc); // Will return newDoc
});
// Second element, an object. Deep equality is used
db.findOne({ b: { bloup: 'blip' } }, function (err, doc) {
console.log(doc); // Will also return newDoc
});
// You can also use comparator queries
db.findOne({ b: { $gt: 6 } }, function (err, doc) {
console.log(doc); // Will also return newDoc
});
});
You don't yet have the power to query for the objects in an array, such as elemMatch, and I may implement that in the future but there is still more basic work to do so I'll close this issue in the meantime :)
Also, note that when I never used arrays containing non-primitive types when I used MongoDB for tldr.io. Instead, I used "foreign keys" (storing an array of ids) and used two queries (one for the main document, the other to get the documents in the array). Mongoose made this process easy.
from nedb.
I'm guessing that comparator queries on properties of objects in arrays don't work - probably a bit much to ask but this doesn't seem to
{"key": "A","tags": [{"tag": 1},{"tag": 2},{"tag": 3}]}
{"key": "B","tags": [{"tag": 1},{"tag": 3}]}
{"key": "C","tags": [{"tag": 1},{"tag": 2}]}
db.find({"tags": {"tag": {$gt: 2}}},...
from nedb.
No, but MongoDB doesn't either. That seems like elemMatch to me.
from nedb.
You're probably right there :)
On 21 June 2013 14:06, Louis Chatriot [email protected] wrote:
No, but MongoDB doesn't either. That seems like elemMatch to me.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/32#issuecomment-19814618
.
from nedb.
MongoDb does searches in array objects and that's one of its benefits.
For your case right query will be: db.find({"tags.tag": {$gt: 2}})
from nedb.
Related Issues (20)
- Question: Is it possible to use promises with this lib. HOT 1
- NPM found 2 high severity vulnerabilities in NeDB, require manual review HOT 10
- NeDB datastore Model needs to be provided
- update the version of underscore dependence! HOT 1
- How to search multiple feilds' "$and"? HOT 4
- Add link to "official" fork HOT 8
- "this library is no longer maintained" HOT 7
- Insert doesn't take place immediately HOT 2
- How to catch abort if the capacity of storage is full??
- $setOnInsert is not work??????
- high vulnerabilities for this package HOT 2
- Error: Cannot create a string longer than 0x1fffffe8 characters HOT 1
- Please update dependency underscore HOT 4
- files
- Data Loss HOT 1
- Request to move repo under NW Userland
- PLEASE !!! Fork this project and create a new one HOT 1
- How to use expireAfterSeconds?
- i have a probleme to photo to nedb db HOT 1
- Regarding the issue of writing permissions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nedb.