Decrypter
Decrypter

Reputation: 3000

datastore - sets a primary key to one of the property fields

I am using gstore-node in my application

const gstore = require('gstore-node')();

const { Schema } = gstore;

const userSchema = new Schema({
  name: { type: String },
  userId: String,
});

I would like to make userId my key. so I can do things like

const userId = '1234';
userSchema.get(userId)

I've tried:

  const entityKey = UserSchema.key(userId);
  const user = new UserSchema({ key: entityKey });

but

 UserSchema.get(userId); // Not Found

How can I make this work?

Upvotes: 0

Views: 145

Answers (1)

Decrypter
Decrypter

Reputation: 3000

Figured it out. The second arg in the Entity creation is the key so const user = new UserSchema({name: 'Homer'}, userId);

This makes userId the key so I can lookup users with the get function

Upvotes: 1

Related Questions