Can you create a compund index including _id or key? - indexing

Suppose I have the following document:
{_id: "mycollection/key",
_key: "key",
users: ["userKeyA","userKeyB","userKeyC"]
}
Can I create a persistent Index for _id and users to speed up my lookup time for user keys?

Yes you can.
db.<collection>.ensureIndex({fields:["users", "_key"], type:"persistent");

Related

How to create a new table with partition key and sort key with AWS-Amplify?

I need to add a sort key and partition key to an existing dynamo db table... I created a new table with a partition key and sort key manual. But when I try to get one separate from the table it gives an error called "The provided key element does not match the schema". For that reason, I want to create a new table with a partition key and sort key. How can I edit my graphql schema and do a amplify push to create a new table? Please help... following is my graphql schema
type Idea #model
{
id: ID!
title: String!
userName: String
category: String!
status:String
OtherCategory: String
description: String
subCategory: String
createdAt: AWSDateTime
updatedAt: AWSDateTime
comments: [Comment] #connection(name: "IdeaComments")
}
Take a look at the new #key directive that was added to Amplify's GraphQL Transformer: https://aws-amplify.github.io/docs/cli/graphql#key

Find namespace records in Redis

How do I find all the records in Redis?
USER_EXCHANGE = table
USER_ID = User ID (primary key)
UID = relationship
The key is stored with the following structure
USER_EXCHANGE:USER_ID:4030:UID:63867a4c6948e9405f4dd73bd9eaf8782b7a6667063dbd85014bd02046f6cc2e
I am trying to find all the records of the user 4030...
using (var redisClient = new RedisClient ())
{
List<object> ALL_UID = redisClient.Get<List<object>>("USER_EXCHANGE:USER_ID:4030:UID:*");
}
What am I doing wrong? Thank you all for your help.
Hi as you're trying to fetch all keys matching a pattern you should use KEYS.
GET won't match patterns. by will retrieve complete full names.
Caution this is a debug function and not a production function.
doc: https://redis.io/commands/keys
Production simple solution, recommanded for you is :
store a list of your key in a LIST
USER_EXCHANGE:USER_ID:4030 => [ uid1, uid2, uid3 ....]
get list of uids for a specific user ID by getting the list.
This is a good practice in REDIS.

Updating an object with Realm without a Primary Key

In my React-Native app, I need to update some objects but I can't do like the tutorial :
realm.write(() => {
// Create a book object
realm.create('Book', {id: 1, title: 'Recipes', price: 35});
// Update book with new price keyed off the id
realm.create('Book', {id: 1, price: 55}, true);
});
Because my objects don't have a primary key (and i don't want them to have primary key)
There is my try :
this.state.realm.write(() => {
this.state.realm.create('Bills', {type: this.state.billType,
creditor: this.state.billCreditor, month: this.state.billMonth,
year: this.state.billYear, price: this.state.billPrice}, true);
});
But this try obviously create an another object ^^
Is someone have an idea for my problem please? Thanks for all =)
Finally, I used UUID as Primary key ^^"
https://www.npmjs.com/package/react-native-uuid
Currently Realm doesn't support updating objects without primary keys. See this GitHub issue.
If you really want to achieve this, you will have to delete the object from Realm and then adding it with the updated values.
However, I wouldn't recommend this method. Creating a primary key in most cases is the optimal solution, so you should reconsider using it. The built in update method will in most cases have a better performance than any method you could write without using primary keys.

Does [js-data] support no primary key?

I have log data that I wish to manage with js-data (http://www.js-data.io/docs/dsdefaults#idattribute) that has no primary key.
Do I need to generate a key or can js-data be configured to allow access to the data without a pk?
Can I get js-data to generate a pk? I have no need to persist this data, just wanted to use the js-data capabilities to query it.
Example:
$provide.factory('syslog', ['DS', function(DS) {
return DS.defineResource({
name: 'log'
});
}]);
$provide.factory('LoggingServices', ['$q', '$filter', '$log', 'syslog', function($q, $filter, $log, syslog) {
function injectMockLogs () {
syslog.inject({
'messages': [
{
'time':'2016-03-29 09:32:43',
'severity':'INFO',
'user':'carolyn',
'auth_type':'RADIUS',
'method':'UI',
'event_id':1107,
'message':'In make_radius_request: Making radius request for user carolyn',
'full_message':'2016-03-29 09:32:44 "info" ns [1107]: RADIUS auth:In continue_radius_auth: Starting RADIUS authentication for user carolyn # 10.217.22.20'
},{
'time':'2016-03-29 09:32:44',
'severity':'INFO',
'user':'carolyn',
'auth_type':'RADIUS',
'method':'UI',
'event_id':1107,
'message':'In make_radius_request: Making radius request for user carolyn',
'full_message':'2016-03-29 09:32:44 "info" ns [1107]: RADIUS auth:In make_radius_request: Making radius request for user carolyn'
},{...
In order for data to be injected into the store (which is an Identity Map), the data needs to have some sort of unique identifier. It's okay if you yourself don't need the items to have a primary key, but it is necessary for JSData.
As of 2.9.0, passing the temporary: true option to inject will cause an id to be generated for each of the items being injected, though your current workaround is a fine approach.

How to update an existing document inside an ElasticSearch index using NEST?

im attempting to do an index update of documents within my elasticsearch index.
a job is run periodically during the day that identifies database records that have been updated since the last time the job ran. i want to be able to update these specific records in the index. any of the fields may have changed in the record.
so i populate a dataset and then loop through the records to populate an instance of my class with all the properties from the database.
each time i want to update the corresponding record in the index or add it if it doesnt currently exist...
within my loop im trying some code like this to do the update...
client.Update<MyContentClass>(u => u
.Id("AU-7zORce3_kxnyDoVLv")
.Index("qubecontent")
//.Doc(new MyContentClass { ESUniqueKey = MyContentClassInstance.ESUniqueKey })
.DocAsUpsert()
.Refresh()
);
im not sure what Id is referencing? is this the id that elasticsearch autogenerates for each indexed record? I do generate an additional unique id within my class but not sure how i reference this?
Can anyone advise how i would perform this index update for a changed record?
The ID field in the upsert is indeed referencing the internal ElasticSearch ID (think of it as the primary key for ES). If you already have your own unique primary key you can use that as the primary key in ES as well. Take these examples:
Example 1: Let ES generate it's own ID
POST test/type1
{
"f1": "record 1",
"f2": "2000-01-01"
}
Result 1:
{
"_index": "test",
"_type": "type1",
"_id": "AU--Dz-Kl6g2APRJ9y7l",
"_version": 1,
"created": true
}
You can see that ES generated it's own primary key of "AU--Dz-Kl6g2APRJ9y7l"
Example 2: Epecify your own ID
POST test/type1/thisIsMyID
{
"f1": "record 1",
"f2": "2000-01-01"
}
Result 2:
{
"_index": "test",
"_type": "type1",
"_id": "thisIsMyID",
"_version": 1,
"created": true
}
Notice how in Example 2 it used the ID that I specified. Once you are using the same primary key as ES then you can run your upsert statement.
NOTE: If you are regenerating the whole document and what you really want to do is overwrite the old vs upsert the old. Then you can just POST again with the same ID and it will overwrite the old record with the new record. Overwriting will be WAY faster than upserting.