Suppose I have an array that contains an object in yeoman prompt:
const getDatabaseName = [
{
type: 'input',
name: 'dbName',
message: 'Please enter your database name:',
default: 'testdb',
store: true
}
]
I know we could use props.dbName to retrieve user input for this object. But, how would I get the input using standard object call?
I tried this: getDatabaseName[0].dbName, but it's undefined.
Related
So I got a connection working using tedious but the options available in node-mssql for handling JSON are something really useful that I would like to have access to.
The documentation for node-mssql says you can pass an object with authentication settings that tedious would use and it will override the user/password properties but it's definitely not doing that. I can confirm because the error message comes back with the value for the user property.
Is there something wrong with the config object?
const sqlConfig = {
server: process.env.SQL_SERVER,
database: process.env.DATABASE_NAME,
user: "root.user",
password: "password",
options:
{
encrypt: true,
authentication: {
type: "azure-active-directory-password",
options: {
userName: "root.options.authentication.options.userName",
password: "password"
}
},
}
};
Here's the example using node-mssql and azure-active-directory-password(supports Azure AD from tedious#4.1.0):
const config = {
server: 'yoursqlserver.database.windows.net',
database: 'yourdb',
authentication: {
type: "azure-active-directory-password",
options: {
userName: "bob#contoso.com",
password: "password",
}
}
}
Ref here:
https://stackoverflow.com/a/58386825/10549281
https://stackoverflow.com/a/56145320/10549281.
https://github.com/tediousjs/tedious/issues/416#issuecomment-441364272
So there are packages for mssql and node-mssql. I installed node-mssql but was working with the documentation for mssql. I am an idiot.
Thanks to everyone who looked at this and especially Leon.
Using "mongoose": "^5.4.21", and Mongo Atlas, I can not seem to connect to my database in my node.js application
I tried to encode my connection string but that gives me Invalid connection string, if I remove encodeURIComponent I get authentication failed
mongoose.connect(encodeURIComponent("mongodb+srv://name:}Izu#[{!6o#cluster-oxzyp.mongodb.net/"), { dbName: "website", useNewUrlParser: true });
You can separate the username and password part of the connecting URI into the options section as shown below:
mongoose.connect("mongodb+srv://cluster-oxzyp.mongodb.net", {
user: 'name', //assuming this is your username
pass: '}Izu#[{!6o', //assuming this is your password
dbName: "website",
useNewUrlParser: true
});
This is probably happening due to the presence of # character in your password. Or you can try doing it like below:
mongoose.connect(`mongodb+srv://name:${encodeURIComponent('}Izu#[{!6o')}#cluster-oxzyp.mongodb.net/`, {
user: '',
pass: '',
dbName: 'website',
useNewUrlParser: true });
I am using validator npm package to validate if email is correct.
All that i need is to send a custom message - Invalid Email
but I am getting this -
User validation failed: email: Invalid Email
const UserSchema = mongoose.Schema({
email:{
type: String,
unique: true,
required: true,
trim: true,
lowercase: true,
validate: [isEmail, 'Invalid Email']
},
});
All is good but when i am catching that error and logging it -
user.save().then(data => {
res.status(201).send(data);
}).catch(err => {
console.log(err.message); // this line here logs out the error message
return res.status(500).send({
message: err.message
});
})
I need this - Invalid Error instead of User validation failed: email: Invalid Email
Thanks in advance!
You have 2 solutions here:
1. Edit the validator package and remove the 'User validation failed' line totally.
2. Split the error message:
var errMessageArray = err.message.split(':');
var messageToReturn = errMessageArray[errMessageArray.length - 1]
I have a migrated Parse application running on Parse 2.1.6. It uses a simple MongoDB 3.0.8 (RocksDB engine) setup, with authentication. The user it's using has the permissions:
[{ "role" : "dbAdmin", "db" : "parse" },
{ "role" : "readWrite", "db" : "parse"}]
When the Parse server boots up or tries to handle any request, I get:
[MongoError: not authorized for query on parse._SCHEMA]
Which seems very weird, given that:
the user clearly has permissions to query any collection on this database,
that same user is indeed able to query this collection via mongo console or robomongo,
Parse.com works normally when using this database, with that same user,
I can actually run the same Parse application locally, pointing to this same remote MongoDB with that user, and it works without such errors.
This is kinda crazy. I get the feeling that I'm missing something pretty basic here. Any thoughts?
UPDATE:
As request, sample code showing how the server is booting:
var api = new ParseServer({ appId: 'the app id',
masterKey: 'the master key',
clientKey: 'client key',
cloud: '/absolute_path/cloud/main.js',
serverURL: 'https://myserver.com/parse',
push:
{ ios:
{ production: false,
bundleId: 'thebundleid.com',
pfx: <Buffer ... > } },
oauth: { facebook: { appIds: 'appId' } },
databaseURI: 'mongodb://user#pass:127.0.0.1:27017'
});
app.use('/parse', api);
new to Sequelize library. From my understanding, 'id' is created automatically by sequelize (and thats what I see in the database). However when I go to 'create' an object it will throw this error:
{ [SequelizeUniqueConstraintError: Validation error]
name: 'SequelizeUniqueConstraintError',
message: 'Validation error',
errors:
[ { message: 'id must be unique',
type: 'unique violation',
path: 'id',
value: '1' } ],
fields: { id: '1' } }
The offending code:
db.Account.create({
email: req.body.email,
password: req.body.password,
allowEmail: req.body.allowEmail,
provider: 'local',
role: 'user'
})
Notice ID is not specified anywhere, neither is it specified in my model definition. Also the query it generates runs fine if I run it in postgres admin:
INSERT INTO "Accounts" ("id","email","role","verifyCode","provider","cheaterScore","isBanned","allowEmail","updatedAt","createdAt") VALUES (DEFAULT,'cat69232#gmail.com','user','','local',0,false,false,'2016-01-27 04:31:54.350 +00:00','2016-01-27 04:31:54.350 +00:00') RETURNING *;
Any ideas to what I could be missing here?
edit:
postgres version: 9.5
stack trace starts here:
/node_modules/sequelize/lib/dialects/postgres/query.js:326
Postgres has a habit of not resetting the next number in the sequence (autoincrement field) after bulk inserts. So if you're doing any pre-filling of the data in an init routine or from a SQL dump file, that's probably your issue.
Check out this post https://dba.stackexchange.com/questions/65662/postgres-how-to-insert-row-with-autoincrement-id