TypeError: Object marks has no method 'forEach' in nodejs mongojs - mongojs

I am writing a nodejs application that uses express and mongojs.The express works fine but when i add mongojs i get an error.
var mongojs = require('mongojs');
var database = "collegeApp";
var collections = "marks";
var db = mongojs(database,collections);
the error shown looks like its a mongojs library error.
TypeError: Object marks has no method 'forEach'
at new Database (/home/justACoder/Desktop/projects/collegeApp/project/node_modules/mongojs/lib/database.js:14:13)
Also i have another project that is not running concurrently but when i run that project no error occurs.It runs fine.

I just found the error.Its the fact that the collections passed was not an array and thats why the forEach function wasn't present.

Related

Why is querying sql_master returnining nothing on some machines?

I recently changed some code I have using SQLite via better-sqlite3 to check if a table exists before running certain import queries.
The code and tests all run fine. But the tests don't pass on our build machines or on another developers machine. The tests are using an in-memory database, the problem hasn't occurred on any non-memory databases though it has only been ran on a half-dozen machines. There are tables in the database and code is able to read/write to them.
It turns out that the query I was using to check what tables I can import from was return an empty result. In fact, if I just query anything at all from sql_master in these cases I get an empty result.
// db is a database from better-sqlite3
private async getAllTables() {
var query = connection.db.prepare(`SELECT name, type FROM sqlite_master`).raw();
return query.all();
}
var allTables = await this.getAllTables();
console.log(`all things in sql_master: ${await allTables.join(", ")}.`);
The console has the following logged on the problematic matchines:
All things in sql_master: .
Locally it prints a list of all the things in sql_master as you'd expected. All the other queries my test code is doing is working as expected (reading and writing to tables besides sql_master).
The database was created like:
db = new Connection(":memory:", { memory: true, fileMustExist: true });

Unity3D Firebase: InvalidOperationException: FirebaseApp was not initialized with a bucket name

I am using the latest version of FirebaseSDK (currently 4.2.1) in my Unity game. I have everything setup as mentioned in the docs. Realtime database and authentication are working fine but I am getting the following error when running in Editor:
InvalidOperationException: FirebaseApp was not initialized with a bucket name.
when I does the following:
StorageReference storageRef = FirebaseStorage.DefaultInstance.RootReference;
But if I make the reference using bucket name its fine, for example:
StorageReference storageRef = FirebaseStorage.DefaultInstance.GetReferenceFromUrl("gs://bucketname");
does not produce an error.
Anybody having any idea what's wrong?
When calling App.Create, you can pass in options via the app options struct. I believe this gets filled automatically, if you are running on device (and it can access the google-services plist/xml) but in the editor, you need to specify it. If you call FirebaseStorage.DefaultInstance.RootReference without doing so, then it won't actually know what the root reference for your project is. (Getting references directly from gs:// links works, since those are absolute.)
Try setting the bucket via AppOptions when you call App.Create().

How can I get current projectId inside Google Cloud Functions?

The question is simple. I need projectId in order to establish connection insde Google Cloud Function. I found the documentation where it said, that projectId is optional parameter and will be checked from GCLOUD_PROJECT, but on deployed function it didn't work.
So it is the question now how can I get the projectId env variable in order to pass it as argument for Datastore connection instance, or what should be done to not pass this id and establish connection with datastore inside Google Cloud Function?
Update 1
I found that I actually can get variable from process.env.GCLOUD_PROJECT, just like any other env.variable.
But, know is the last question, is it actually possible to use #google-cloud/datastore without any configuration object?
You can get project ID as const projectId = process.env.GCP_PROJECT.
But for some reason the environmet variable "GCP_PROJECT" is not set when running the emulator. Instead the deprecated variable name "GCLOUD_PROJECT" is the one to select. So you might try them both.
const projectId = process.env.GCP_PROJECT || process.env.GCLOUD_PROJECT
The answer depends on which runtime you are using.
If your using Python 3.7 and Go 1.11 you are in luck. Use
process.env.GCP_PROJECT
If using any of the new runtimes, bad luck, either access the metadata server, or google suggests
Note: If your function/app requires one of the environment variables from
an older runtime, you can set the variable when deploying your
function. For example:
gcloud functions deploy envVarMemory \
--runtime nodejs10 \
--set-env-vars FUNCTION_MEMORY_MB=2Gi \
--memory 2Gi \
--trigger-http
If using terraform:
resource "google_cloudfunctions_function" "my-function" {
name = "my-function"
runtime = "nodejs16"
environment_variables = {
GCP_PROJECT = var.project_id
}
#...
}
Under Cloud Functions v2 public preview (Oct 2022), there's a section called built-in parameters that allows require of Project ID, Database URL and Storage bucket.
Presumably also Location ID ("Default GCP resource location") would be listed here, though that's not in the current documentation.
I did not get that to work.
However, this does:
const firebaseConfig = JSON.parse( process.env.FIREBASE_CONFIG );
const locationId_maybe = firebaseConfig.locationId || null;
const projectId = firebaseConfig.projectId;
const databaseURL = firebaseConfig.databaseURL;
The env.var. is always defined. locationId is defined only if there's an active Firebase project. This makes sense, since it needs access to the GCP project in the cloud.
Firebase CLI 11.15.0
As I wrote in update 1 we can get all the information about environment from the process.env variable.
And the second question about configuration object for #google-cloud/datastore, it actually can work without any options. It will trying to fetch all required parameters from environment variables. So, it didn't work beacuase of error in my code.
if it's an HTTP function, we can use the URL to figure out the current project and region with req.header('host')
For any runtimes after node 8 you can use https://www.npmjs.com/package/gcp-metadata
const gcpMetadata = require('gcp-metadata');
export const getGCPProjectIdFromMetadata = async () => {
const isAvailable = await gcpMetadata.isAvailable();
if (!isAvailable) {
return undefined;
}
return gcpMetadata.project('project-id');
};
This will also work across any other instances you wish to launch (such as app engine).
When having deployed with firebase deploy there's:
functions.config().firebase.projectId
functions.config().firebase.databaseURL
functions.config().firebase.storageBucket
functions.config().firebase.locationId

Meteor minimongo insert method not working

I was following the meteor tutorial from meteortips and I got to the part where you create a collection in the browser's console. Creating the collection works, but it doesn't let me insert anything into it.(PlayersList = new Meteor.Collection('players');)
Please see below:
PlayersList.insert({ name: 'Alex', score: 42 });
"rpPamgZEZM9opCzHz"
debug.js:41 insert failed: Method not found
What's weirder is that I even get back the hash as if the insert worked.
Typing PlayersList.find().fetch(); returns an empty array :(
I'm using the latest version of Meteor on Windows 8.1 with MongoDB version 2.6
If anybody could help me, I would be very thankful :)
You have defined the collection PlayersList = new Meteor.Collection('players'); on the client but it has not been defined on the server.
If you have something like if(Meteor.isClient) {..} (or in the /client) directory the code won't run on the server. Make sure you also place a PlayersList = new Meteor.Collection('players'); in the if(Meteor.isServer) (or the /server) directory.
The best thing to do is place it outside both in the root directory so it runs on both the client and server.
When you insert the document on the client the message is transmitted to the the server & it tries to insert it into the database. The collection isn't defined on the server side so it rejects it with the message method not found.

Flash Builder, Air - NativeProcess API error

In all samples for how to use Native Process API i can see the following line:
process = new NativeProcess();
when i try to run the sample i get an error:
Description Resource Path Location Type
1120: Access of undefined property process. testProj.mxml /testProj/src line 61 Flex Problem
what should i do? this process is not declared anywhere.
this is the right way to define a var in flash as a NativeProcess type
var process:NativeProcess;

Resources