Skip to content
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

[firestore-emulator: datastore-mode] Namespace queries return empty array #6932

Open
aalej opened this issue Mar 28, 2024 · 0 comments
Open

Comments

@aalej
Copy link
Contributor

aalej commented Mar 28, 2024

[REQUIRED] Environment info

firebase-tools: v13.6.0

Platform: macOS Sonoma 14.4

node: v20.10.0

gcloud: v470.0.0

cloud-firestore-emulator: v1.19.4

[REQUIRED] Test case

MCVE - https://github.com/aalej/issues-6932

Alternatively, make a directory containing the ff files:

src/index.ts
import { Datastore } from "@google-cloud/datastore";

const datastore = new Datastore({
  projectId: "some-testproject",
});

export async function getNamespaces() {
  const query = datastore.createQuery("__namespace__").select("__key__");
  const [entities] = await datastore.runQuery(query);
  const namespaces = entities.map((entity) => entity[datastore.KEY].name);
  return namespaces;
}

export async function addEntity(namespace: string, kind: string[], data: any) {
  const entityKey = datastore.key({
    path: kind,
    namespace,
  });
  const entity = {
    key: entityKey,
    data,
  };
  await datastore.save(entity);
}

async function main() {
  await addEntity("Tasks", ["Work Tasks"], {
    category: "Personal",
    done: false,
    priority: 4,
    description: "Learn Cloud Datastore",
  });

  const namespaces = await getNamespaces();
  console.log(namespaces);
}

main();
tsconfig.json
{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "outDir": "lib"
  },
  "include": ["src"],
  "exclude": []
}
package.json
{
  "version": "1.0.0",
  "description": "",
  "main": "lib/index.js",
  "scripts": {
    "build": "tsc",
    "build:watch": "tsc --watch"
  },
  "devDependencies": {
    "@google-cloud/datastore": "^8.6.0",
    "typescript": "^5.4.3"
  }
}

[REQUIRED] Steps to reproduce

Testing while connected to the emulator

  1. Run npm i
  2. Run gcloud emulators firestore start --database-mode=datastore-mode --host-port=127.0.0.1:8081
  3. On a separate terminal, run export DATASTORE_EMULATOR_HOST=127.0.0.1:8081
  4. Run npm run build
  5. Run node . or node lib/index.js

[REQUIRED] Expected behavior

Console logs should show the namespaces on Datastore emulator.

When connecting to production, console logs show the namespaces on Datastore:

[ 'Tasks' ]

Steps to test on a production environment:

  1. Run unset DATASTORE_EMULATOR_HOST
  2. Run export GOOGLE_APPLICATION_CREDENTIALS=<path_to_service_account_key.json>
  3. Run npm run build
  4. Run node . or node lib/index.js

[REQUIRED] Actual behavior

When connected to the emulator, console log outputs an empty array

[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants