yurysolovyov / dexie-mongoify Goto Github PK
View Code? Open in Web Editor NEWDexie.js plugin with MongoDB-like API
License: MIT License
Dexie.js plugin with MongoDB-like API
License: MIT License
Update method should have a following signature as per mongo native driver:
.update(query, updates[, options]); // -> Promise
Let's implement upsert
option first.
@YuriSolovyov Are there any plans to support query projections so we can just get specific document fields returned. See: https://docs.mongodb.org/manual/reference/method/db.collection.find/
ATM it is complete mess.
Does it support $regex operator? I want to query to see if a string field contains certain substring.
I've just downloaded the latest dexie.js and the latest dexie-mongoify.min.js and am getting "TypeError: Cannot read property 'push' of undefined"
It appears as though quite a bit has changed in dexie.js lately
Please, add integration with bower.
I was just trying to familiarize myself with the codebase to work on the fulltext search item, but after doing a fresh clone of master
and doing npm run test
, the three $sort operator tests fail.
I tried putting some console logs in the sort operator function, but I can't get the logs to show up. Probably because I don't understand something with Karma. This option didn't lead to the logs showing up:
browserConsoleLogOptions: {
level: 'log'
},
By the way, would you be open to a PR to update all dependencies, and possibly implement some typings?
What about complex queries with nested $and/$or?
products.find({"$and":[{"$or":[{"pgr_id":{"$eq":6}},{"pgr_id":{"$eq":10}}]},{"name":{"$eq":"test"}}]})
with this kind of query i get the error
Uncaught TypeError: Cannot read property '0' of undefined.
Is this not supported or another syntax required?
I am trying to add an object to an existing array which in inside a nested object. The structure looks similar to below
{
Name : 'John',
age : 33,
tags : {
skill: [{
first: '.NET',
second: 'JAVA',
third: [{special1:'sleep'},{special2:'eat'}]
}]
}
}
I have tried many way to push object special3:'run' to skill.third but without success. My last attempt looked something like this
const pathObject = {};
const fullPath = 'result.tags.skill[3].third';
pathObject[fullPath] = {special3:'run'};
db.inspections.update(id, pathObject);
The object is added outside and not inside the array 'third' something like below
{
Name : 'John',
age : 33,
tags : {
skill: [{
first: '.NET',
second: 'JAVA',
third: [{special1:'sleep'},{special2:'eat'}]
}]
skill[3]: {
third: {special3:'run'}
}
}
}
I wish to know if there a way to add to arrays in nested object using dexie-mongoify? Help is appreciated.
Should make mongoify less racy and possibly a bit faster
The find example:
db.collection('people').find({ age: 30 }).then(function(people) {
// people 30 years old
});
isn't correct as find() does not return a promise.
@YuriSolovyov I just found mongoify yesterday and have already put it to good use. Many thanks for creating this. The Dexie site needs a list of add-ons, which I'll suggest to them.
One thing I'd like is the ability to use the Mongodb upsert
option in update()
I've done a crude implementation in my own code which I can show you, if it's of interest.
It would also be good if functions returned the same values as the native mongo driver. For example update
returned WriteResult
I'm using MongoDb on the server in a Node.js app and have made a start using Dexie.js in the Browser. mongoify will certainly be a most welcome help in unifying code for my Web app Clibu, http://clibu.com
Could you please write some Wiki content on how mongoify uses indexes. I've had a quick look through the code, but it needs more than that.
We desperately need a unified database api and functionality across Server & Browser, as right now it's a mess. Interestingly there is an job advertisement on the MongoDb site for someone to work on a Browser version of Mongodb!
We have IndexedDB in the Browser which is complex to use, but has a good range of features (secondary indexes, sub-document indexes etc). And Dexie is great.
And for an in-process database on Node.js we really only have leveldb which sadly lacks secondary indexes, sub-document indexes, composite keys etc. The are good wrappers such as levelup, linvodb3 https://github.com/Ivshti/linvodb3 which provides a mongodb api, but currently uses in-memory indexes.
Hi All,
Thanks for this great library! I was talking with the folks at textile.io, who are building js-threaddb. It is a local-first database which will sync to the distributed web and currently depends on this library.
IMO, to power serious applications that use the browser for its primary storage mechanism, there needs to be a full-text search capability on the database. I submitted this issue about the topic. Are there any plans to implement full-text search via the $text
search operator in dexie-mongoify
?
A couple examples of "prior art" on the topic are https://github.com/dfahlander/Dexie.js/blob/master/samples/full-text-search/FullTextSearch.js and https://github.com/yathit/ydn-db-fulltext.
When you have a chance, please let me know if you have any thoughts on this topic and whether you think it makes sense to incorporate with dexie-mongoify
. Thanks!
@YurySolovyov I have found two problems with table.update() which I don't think are new.
table`.update( { 'panel': panel }, { 'show': show }, { upsert: true } )
Update createObjectForUpsert()
var createObjectForUpsert = function(query, update) {
......
// If no Upsert operators were spec'd we use update as is. ie. i.e. update contains only field and value pairs. NF 2/01/2017
// ref: https://docs.mongodb.com/manual/reference/method/db.collection.update/#update-parameter
if ( Object.getOwnPropertyNames( objectFromUpdate ).length === 0 )
objectFromUpdate = update;
return assign(objectFromQuery, objectFromUpdate);
};
table`.update( { 'panel': panel }, { 'show': show }, { upsert: true } )
panel
object exists, but the show
property doesn't. My fix for this is:var createPlainPropertyUpdater = function(update, objectKeys) {
var keys = objectKeys || Object.keys(update);
return function(item) {
// Replace entire document.
// ref: https://docs.mongodb.com/manual/reference/method/db.collection.update/#example-update-replace-fields
keys.forEach(function(key) {
// if (has(item, key)) { // this prevents plain update with values that don't already exist from working. ex. existing doc { a: "1" } -> update { b: "2" } NF 2/01/2017
item[key] = update[key];
// }
// TODO: item[ key ] which aren't present in update[] need to be removed. Can't be done here as we only have the update spec. Maybe do t in createPlainModifier(). NF 2/01/2017
});
};
};
Note that according to the MongoDB docs for collection.update()
if no update modifiers are specified the entire document is replaced. At present this is not the case as per my TODO comment above.
I have not exhaustively tested these two fixes, which may possibly break other scenarios so please have a close look at them.
Neville
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.