arangodb document key length best practice - arangodb

I am wokring on arangodb and was wondering weather doucment key size will affect database size.
I am not sure how arango db stores data but does key length of document affects db size ?
{
'username': 'testuser',
'password': 'testpass'
.
.
.
.
}
VS
{
'u': 'testuser',
'p': 'testpass'
.
.
.
.
}

Related

Dynamodb Add or Update key in dict

I have a dynamodb table with the following structure:
'Items': [
{'user_id': 'myuser',
'owes_to': {
'youruser': '10',
'user3': '20'
}
}]
Is it possible in dynamodb to create a new user key in owes_to or if it already exists add to the value of that key?
In example in two calls:
Add 'user4' with value 20, It doesnt exist so create the user4 key with value 20)
Next time update user4 value 20 to 40, This time key already existed so add the 20 to the existing value
It's possible, update expression will be similar to this:
update_request = {
Key={'user_id': ':id'},
UpdateExpression='SET owes_to.#user_name = if_not_exists(owes_to.#user_name, :default_val) + :val',
ExpressionAttributeNames={
'#user_name': <your_user_name>
}
ExpressionAttributeValues={
':id': 'myuser',
':val': <your_update_value>,
':default_val': 0
}
}
Note the if_not_exists(owes_to.#user_name, :default_val) construction. It will take value of the user if it exists or take value specified in :default_val if it doesn't.
More about adding and updating map values in official docs

Sequelizer : JSONB postgres query not working

I am trying to get the records on the basis of some key that are in jsonb, i am using sequelizer as ORM and postgres as a DB . I am getting empty array of leads unexpected ...
whereArr.push(db.where(
db.cast("dataJson.basicInfo.firstName.value", 'text'),
{ [Op.iLike] : "%k%" }
));
searchBy = {
where: {
...whereArr
}
};
let leads = await Lead.findAndCountAll({
...searchBy,
...orderBy,
...paginate
});
The code work fine if i am using the column name other than jsonb's column .
I am unable to figure out the issue. please guide how can i achieve that .
Thank You

How to assign the value of a field to another in a single mongo Query

Suppose you have a mongo record :
{
_id : 1234,
x: 12,
y: 34
}
I need a query that will update an particular _id in such a way that
x = y;//assign the value of y to x
y = new Date().getTime();//assign current time to y
for a particular _id.currently I am reading the id modifying the entity and updating it.Is this possible to do it in a single query? what would be it's equivalent using Mongoose
You can't do that unless you use the $where operator. But you should avoid doing this because using $where may cause a drop of performance as mentioned in the documentation:
$where evaluates JavaScript and cannot take advantage of indexes. Therefore, query performance improves when you express your query using the standard MongoDB operators (e.g., $gt, $in).
db.collection.update({ '$where': function() { return this.x === this.y }},
{'$set': { 'y': new Date().getTime() }}
)
The best way is to run two queries like you did. One to retrieve the _id value and the other to update your documents.
You can't assign y's value to x and new Date().getTime() to y using a single MongoDB query. You need to first retrieve y value using the .findOne() method and then use another query to update the document.
var y = db.collection.findOne({ '_id': <given ObjectId()> },
{ 'y': 1, '_id': 0 }
)['y'];
db.collection.update( { '_id': <given ObjectId()> },
{ '$set': { 'x': y, 'y': new Date().getTime() } }
)

Querying a Riak DB by a Subkey

I'm using riak-js and node.js
If I have a document as follows:
{ 'skey1': 'val1',
'skey2': 'val2',
......,
'skeyn': 'valn'
}
How can I return a document that has skey2 = 'val2'? How would this be done in node.js / riak-js?
If your storage backend is riak_kv_eleveldb_backend, you can use secondary indexing.
db.save('airlines', 'KLM', {country: 'NL', established: 1919}, {index: {country: 'NL', established: 1919}});
and query like
db.query('airlines', {country: 'NL'});
(the above snippets shamelessly stolen from riak-js.org

Cassandra getting data (query on different attributes)

how i can get data from Cassandra using value
posts = {
'1': { //this post id
'user_id': '4',
'body': 'This is awesome!',
},
}
i cen get the post using post id
can i get posts related to certain user
i mean get post related to user_id=4 like an example (query using user_id attribute)
regrads
For that you will need to maintain your own (secondary) index.
e.g
userIds = {
'4': { //this user id
'post_id': '1'
},
}

Resources