I'm trying to use the Elmongo plugin for Node.js and I'm having some trouble with the plugin. Here is my code:
var mongoose = require('mongoose');
var elmongo = require('elmongo');
var Schema = mongoose.Schema;
var twitterSchema = new Schema ({
id: {type: Number, index: {unique: true, dropDups: true}},
created_at: Date,
user: [{
id: Number,
name: String,
screen_name: String,
location: String
}],
text: String,
keywords: []
});
twitterSchema.plugin(elmongo);
var Tweets = mongoose.model('Tweets', twitterSchema);
twitterSchema.sync(function(err, numSynced){
console.log("number of tweets synced: " + numSynced);
});
twitterSchema.search({query: 'flu'}, function(err, results){
console.log('search results: ' + results);
});
exports.Document = function(db) {
return db.model('Tweets');
};
The error message I'm getting is:
module.js:340
throw err;
^
Error: Cannot find module 'elmongo'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/Documents/UCIMedCenterProject/MedStream-feature.sentiment-analysis/models.js:2:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
I looked up some of the errors and what I get is that I need to reinstall the module, but that didn't work either. Any help?
You should install this module in your project directory (go to your project directory in command line and then run "npm install elmongo")
You should check inside node_modules folder if any folder with name elmongo is present. If not try installing the module again.
Try installing as administrator.
sudo npm install elmongo
Related
I'm trying to make a model for my dcauser table. I get stuck because it returns an error 'Unrecognized datatype for attribute'. Now i don't know if i messed something up in the database or is sequelize not working correctly with my DB or did i mess something up in the code below. I followed some guides but i get always stuck on the same problem i mentioned above.
var Sequelize = require('sequelize');
var sequelize = new Sequelize('postgres://postgres:xpwdx#localhost:xportx/xdbx');
const UserSchema = sequelize.define(
'dcauser',
{
userid: {
type: Sequelize.Integer,
allowNull: false,
}
}
);
module.exports = UserSchema;
i get the following error:
C:\Users\luka\source\repos\dcaBotManager\node_modules\sequelize\lib\model.js:1005
throw new Error(`Unrecognized datatype for attribute "${this.name}.${name}"`);
^
Error: Unrecognized datatype for attribute "dcauser.userid"
at C:\Users\luka\source\repos\dcaBotManager\node_modules\sequelize\lib\model.js:1005:15
at C:\Users\luka\source\repos\dcaBotManager\node_modules\lodash\lodash.js:13401:38
at C:\Users\luka\source\repos\dcaBotManager\node_modules\lodash\lodash.js:4905:15
at baseForOwn (C:\Users\luka\source\repos\dcaBotManager\node_modules\lodash\lodash.js:2990:24)
at Function.mapValues (C:\Users\luka\source\repos\dcaBotManager\node_modules\lodash\lodash.js:13400:7)
at Function.init (C:\Users\luka\source\repos\dcaBotManager\node_modules\sequelize\lib\model.js:1001:28)
at Sequelize.define (C:\Users\luka\source\repos\dcaBotManager\node_modules\sequelize\lib\sequelize.js:428:11)
at Object.<anonymous> (C:\Users\luka\source\repos\dcaBotManager\src\models\user.model.js:14:30)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:\Users\luka\source\repos\dcaBotManager\src\models\index.js:2:23)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:\Users\luka\source\repos\dcaBotManager\src\config\passport.js:3:18)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
The integer keyword must be in uppercase
{
userid: {
type: Sequelize.INTEGER,
allowNull: false,
}
}
INTEGER must be in uppercase. See
https://sequelize.org/v5/manual/data-types.html
Though you should start using DataTypes.INTEGER instead.
https://sequelize.org/master/variable/index.html#static-variable-DataTypes
var kafka = require('kafka-node');
Producer = kafka.Producer;
KeyedMessage = kafka.KeyedMessage;
client = new kafka.Client();
producer = new Producer(client);
km = new KeyedMessage('key', 'message');
payloads = [
{ topic: 'topic1', messages: 'hi', partition: 0 },
{ topic: 'topic2', messages: ['hello', 'world', km] }
];
producer.on('ready', function ()
{
producer.send(payloads, function (err, data)
{
console.log(data);
});
});
producer.on('error', function (err) {});
//error for that code
baaz#bit:~$ node kafka1.js
/home/baaz/node_modules/kafka-node/lib/codec/snappy.js:18
var SNAPPY_MAGIC = Buffer.from(SNAPPY_MAGIC_BYTES).toString('hex');
^
TypeError: this is not a typed array.
at Function.from (native)
at Object.<anonymous> (/home/baaz/node_modules/kafka-node/lib/codec/snappy.js:18:29)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (/home/baaz/node_modules/kafka-node/lib/codec/index.js:4:19)
at Module._compile (module.js:425:26)
Short Answer :
Either increase the node version above 4.5 or
use "kafka-node": "1.6.2" or lesser
Long Answer
with node 4.5 and above, node deprecated the old way of creating buffer via a constructor, so all node js version below 4.5 do not have new that support. and kafka-node version > 1.6.2 uses the buffer.from to create the buffer so we have the compatibility issues.
Cheers
Happy coding
I have a mongoose schema defined as such,
var userSchema = mongoose.Schema({
token: String,
school: [{name: String, grade: String}]
});
As you can see it is "school" with two values of strings inside it.
I am trying to push in values like this,
app.post('/array', function(req, res) {
user.find({
token: "c30a2402dcd8e4580cef8177516e8c57149425bf961a254fd79cf7b7280a6af0adf620d210c8b66989fe7fd35a3adc2756ec2089b415d27c1a1c097e88bc4666"
}, function(err, users) {
if (users.length != 0) {
user.findOne({
token: "c30a2402dcd8e4580cef8177516e8c57149425bf961a254fd79cf7b7280a6af0adf620d210c8b66989fe7fd35a3adc2756ec2089b415d27c1a1c097e88bc4666"
}, function(err, doc) {
doc.ar.push("sss", "A");
doc.save();
});
} else {}
});
});
But the push does not work and gives me an error that I cannot get rid of.
doc.ar.push({"sss","A"});
^
SyntaxError: Unexpected token ,
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (C:\..\app.js:27:1)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:146:18)
at node.js:404:3
Is there a way to easily push values in?
That's a simple JavaScript syntax error. You probably want this:
doc.ar.push({name: "sss", grade: "A"});
i tried the following sample code:
var es=require("elasticsearch");
var ejs = require("ejs");
var client = new es.Client({
host: 'localhost:9200',
log: 'trace'
});
client.ping({
requestTimeout: 3000,
// undocumented params are appended to the query string
hello: "elasticsearch"
}, function (error) {
if (error) {
console.error('elasticsearch cluster is down!');
} else {
console.log('All is well');
}
});
client.search({
index: 'message-1',
type: 'message',
body: ejs.Request().query(ejs.MatchAllQuery())
}).then(function (resp) {
var hits = resp.hits.hits;
}, function (err) {
console.trace(err.message);
});
i am getting the following error when i try to run: node metric.js
/home/karunakar/test/metricagg/metric.js:27
body: ejs.Request().query(ejs.MatchAllQuery())
^
TypeError: Object #<Object> has no method 'Request'
at Object.<anonymous> (/home/karunakar/test/metricagg/metric.js:27:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:929:3
i could not locate the problem.
-- Thanks
You want the elastic.js module and not ejs, which is a templating engine module.
You can keep the first require("elasticsearch") but the second one should be require("elastic.js") instead of require("ejs")
I am running the code in the tutorial part of node-mysql and its giving me error
Code
var MySQLPool = require("mysql-pool").MySQLPool;
var pool = new MySQLPool({
poolSize: 4,
user: 'root',
password: 'root',
database: 'test'
});
pool.query("SELECT 'Hello, World!' AS hello", function(err, rows, fields) {
if(err) throw err;
console.log(rows[0].hello);
});
for(var i = 0; i < 10; ++i) {
pool.query("SELECT SLEEP(2), ? AS i", [i], function(err, rows, fields) {
if(err) throw err;
console.log("Slept: " + rows[0].i);
});
}
ERROR:
/home/comapq/Works/Nodejs/Codes/node_modules/mysql-pool/lib/mysql-pool/pool.js:158
for(var key in Client.prototype) {
^
TypeError: Cannot read property 'prototype' of undefined
at MySQLPool._populate (/home/comapq/Works/Nodejs/Codes/node_modules/mysql-pool/lib/mysql-pool/pool.js:158:23)
at new MySQLPool (/home/comapq/Works/Nodejs/Codes/node_modules/mysql-pool/lib/mysql-pool/pool.js:44:7)
at Object. (/home/comapq/Works/Nodejs/Codes/test-mysql-3.js:2:12)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
After a bit of research I found the problem. You probably installed mysql like this:
npm install mysql
This grabs the latest mysql package that is 2.0.0-alpha5(development phase, mostly untested). You need to install the latest stable version of mysql:
npm install mysql#0.9.6