-
Notifications
You must be signed in to change notification settings - Fork 831
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
How i can select document #1885
Comments
|
|
@jsteemann i create ORM for your database https://www.npmjs.com/package/ormjs
I can write a sql query builder. need one? =) |
While it may be tempting to support query patterns in the fashion of byExample(), they would all be very limited in scope and have to deal with ambiguities - in your suggested Regarding ORM, make sure you read the following discussion: arangodb/arangojs#215 There is already a query builder for JavaScript (e.g. Node.js): https://github.com/arangodb/aqbjs |
@jsteemann how i can select this document by session key, and type == 'mobile' ? userDocument = {
name: 'Ololo',
age: 11,
sessions: [
{key: 324342, type: 'mobile'},
{key: 675604, type: 'pc'}
]
}
this is not correct, i need key and type in ONE session maybe like this:
no? |
Hi,
However, you should note that this query can not make use of indices, which is going to limit scalability. You should rather use one document per session, and join in the payload you need:
You then can then create an index on sessions.key and doc.userID which will give you acceptable execution times even if your data grows. |
you could also use a graph to map userDoc -> session. Then the query is
|
@Simran-B how AQL handles it?
|
It seems easier to create a 2 collections, Sessions and Users sessionDoc = {
userId: String
key: String
}
session = await Sessions.getByExample({key:key})
user = await Users.get(session.userId) It will be faster because of the indexing? |
@baslr: without bind parameters:
With bind parameters:
Note that there is a problem with attributes that contain dots in 2.x. Above examples work in 3.x and you can also have dots in the attribute keys without problems. @uMaxmaxmaximus: Another variant, that cannot use indexes either however, is to use inline filters. This can be handy to return just the matching sessions, e.g.
|
how can I index user.sessions[*].key and make it unique? |
It's currently not possible to index sub-objects of array elements. You can index the individual elements of an array, but not a certain attribute of objects nested in the array. In order to index your data and add a unique constraint you will have to change your data model (pull out sessions into a separate collection and link them with users). |
@Simran-B Look how elegant it is done in my ORM: import Model from '../core/model'
class User extends Model {
static schema = {
name: String,
age: Number,
}
async startSession() {
let key = Math.random() + ''
await Session.add({user: this, key: key})
return key
}
static async getBySessionKey(key) {
let session = await Session.findOne({key: key})
return await session.user
}
}
class Session extends Model {
static schema = {
key: String,
user: User,
}
} Using (async function () {
let user = await User.add({name: 'Ашот', age: 3333})
let key = await user.startSession()
let usr = await User.getBySessionKey(key)
console.log(usr) // tadaa
})() What do you think? Elegantly? =) |
i use arangojs for nodejs
how i can select this document by session key ?
logic: if any object from sessions array have key 324342, select this user
The text was updated successfully, but these errors were encountered: