I am using App Engine flexible environment with Node.js and am trying to store and retrieve entities in Cloud Datastore.
The following code successfully creates a new Event Entity:
/* Create event */
router.post('/', function(req, res, next) {
const eventKey = datastore.key('Event');
datastore.save({
key: eventKey,
data: req.body
})
.then(() => {
console.log('New event created');
res.json({id: eventKey.id});
})
.catch((err) => { next(err); });
});
However, the following returns an empty array when I provide the previously returned id:
/* Get an event */
router.get('/:id', function(req, res, next) {
console.log(req.params.id);
var eventKey = datastore.key(['Event', req.params.id]);
datastore.get(eventKey)
.then((event) => {
console.log(event);
res.json(event);
})
.catch((err) => { console.log(err); next(err); });
});
I seem to be using datastore.get correctly and to do what the docs is telling me to do.
Any idea why I cannot get the entity I previously created?