Phaser not loading multiple createLayer - phaser-framework
I am creating a small Phaser arcade game using Tiled for the map. My maps loads the ground asset however I am not able to load the platforms for some reason. I followed this tutorial :https://phaser.io/examples/v3/view/tilemap/multiple-tilesets but still only the ground tiles are rendered without the platforms. What am I doing wrong and how can I load the platforms as well. There isn't any error in the console. Here is my code:
let config = {
type: Phaser.AUTO,
width: 800,
height: 500,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 300 },
debug: false
}
},
scene: {
preload: preload,
create: create,
}
};
let windowWidth = 800
let widnowHeight = 500
new Phaser.Game(config)
function preload ()
{
this.load.image('sky', require('../assets/sky.png'));
this.load.image('jungle', require('../assets/jungle.png'));
this.load.image('ground', require('../assets/tiles/ground-transp.png'))
this.load.image('small-platform', require('../assets/tiles/small-platform-removebg-preview.png'))
this.load.tilemapTiledJSON('Ground', require('../assets/tutorial-level.json'));
}
function create () {
this.bg = this.add.image(windowWidth / 2, widnowHeight / 2, 'sky');
this.bg = this.add.image(windowWidth / 2, widnowHeight / 2, 'jungle');
this.bg.setDisplaySize(windowWidth, widnowHeight);
const map = this.make.tilemap({ key: 'Ground' })
const tileset = map.addTilesetImage('ground', 'ground')
const platformTileset = map.addTilesetImage('small-platform', 'small-platform')
map.createStaticLayer('Ground', [tileset, platformTileset])
}
and my map:
{ "compressionlevel":-1,
"height":8,
"infinite":false,
"layers":[
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
"height":8,
"id":1,
"name":"Ground",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":14,
"x":0,
"y":0
},
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"height":8,
"id":4,
"name":"Platform",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":14,
"x":0,
"y":0
},
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"height":8,
"id":5,
"name":"MossPlatform",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":14,
"x":0,
"y":0
},
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"height":8,
"id":7,
"name":"BigMossPlatform",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":14,
"x":0,
"y":0
}],
"nextlayerid":8,
"nextobjectid":1,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.9.1",
"tileheight":64,
"tilesets":[
{
"columns":1,
"firstgid":1,
"image":"..\/..\/..\/Downloads\/ground-transp.png",
"imageheight":64,
"imagewidth":58,
"margin":0,
"name":"ground",
"spacing":0,
"tilecount":1,
"tileheight":64,
"tilewidth":58
},
{
"columns":1,
"firstgid":2,
"image":"..\/..\/..\/Downloads\/jungle-platform.png",
"imageheight":66,
"imagewidth":129,
"margin":0,
"name":"jungle-platform",
"spacing":0,
"tilecount":1,
"tileheight":66,
"tilewidth":129
},
{
"columns":1,
"firstgid":3,
"image":"..\/..\/..\/Downloads\/small-platform-removebg-preview.png",
"imageheight":72,
"imagewidth":153,
"margin":0,
"name":"small-platform",
"spacing":0,
"tilecount":1,
"tileheight":72,
"tilewidth":153
},
{
"columns":1,
"firstgid":4,
"image":"..\/..\/..\/Downloads\/large-platform.png",
"imageheight":54,
"imagewidth":244,
"margin":0,
"name":"big-platform",
"spacing":0,
"tilecount":1,
"tileheight":54,
"tilewidth":244
},
{
"columns":1,
"firstgid":5,
"image":"..\/..\/..\/Downloads\/large-platform-removebg-preview.png",
"imageheight":54,
"imagewidth":244,
"margin":0,
"name":"large-platform",
"spacing":0,
"tilecount":1,
"tileheight":54,
"tilewidth":244
}],
"tilewidth":58,
"type":"map",
"version":"1.9",
"width":14
}
You need to create each layer, that you want to display. So If you want to display all layer from your JSON map file, you would have to add the following three lines of code:
(if those layers also use the same tilesets)
map.createStaticLayer('Platform', [tileset, platformTileset])
map.createStaticLayer('MossPlatform', [tileset, platformTileset])
map.createStaticLayer('BigMossPlatform', [tileset, platformTileset])
Related
Dijkstra algorithm for the shortest path using adjacency matrix
I have tried to implement the Dijkstra algorithm in python as: from collections import defaultdict class Graph: def minDistance(self,dist,queue): minimum = float("Inf") min_index = -1 for i in range(len(dist)): if dist[i] < minimum and i in queue: minimum = dist[i] min_index = i return min_index def printPath(self, parent, j): if parent[j] == -1 : print (j) return self.printPath(parent , parent[j]) print(j def printSolution(self, dist, parent): src = 0 print("Vertex \t\tDistance from Source\tPath") for i in range(1, len(dist)): print("\n%d --> %d \t\t%d \t\t\t\t\t" % (src, i, dist[i])), self.printPath(parent,i) def dijkstra(self, graph, src): row = len(graph) col = len(graph[0]) dist = [float("Inf")] * row parent = [-1] * row dist[src] = 0 queue = [] for i in range(row): queue.append(i) while queue: u = self.minDistance(dist,queue) queue.remove(u) for i in range(col): if graph[u][i] and i in queue: if dist[u] + graph[u][i] < dist[i]: dist[i] = dist[u] + graph[u][i] parent[i] = u self.printSolution(dist,parent) It takes list of 36 elements as input. Below is the input list with weights/costs: [[0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0]] However when I am executing: g= Graph() g.dijkstra(graph,35) #src=35 I am getting this error: --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-166-4785fe512432> in <module> 1 g= Graph() 2 graph = adj ----> 3 g.dijkstra(graph,35) <ipython-input-146-4fd492228481> in dijkstra(self, graph, src) 86 87 # remove min element ---> 88 queue.remove(u) 89 90 # Update dist value and parent ValueError: list.remove(x): x not in list I am confused why this happening with queue.remove(u) line. For example,the output should be: Vertex Distance Path 0 -> 2 12 0 1 2 Can someone point out the error in the code? Please resolve this issue. Thank you!
Tailwind CSS extend standard colors in tailwind.config.js. When I try to extend colors, all other colors are deleted
When I try to add some colors to tailwind.css all the other colors are deleted. Here is my tailwind.config.js file: const defaultTheme = require('tailwindcss/defaultTheme'); module.exports = { purge: [ './vendor/laravel/jetstream/**/*.blade.php', './storage/framework/views/*.php', './resources/views/**/*.blade.php', ], theme: { extend: { fontFamily: { sans: ['Nunito', ...defaultTheme.fontFamily.sans], }, }, // colors: { // smoke: { // darkest: 'rgba(0, 0, 0, 0.9)', // darker: 'rgba(0, 0, 0, 0.75)', // dark: 'rgba(0, 0, 0, 0.6)', // DEFAULT: 'rgba(0, 0, 0, 0.5)', // light: 'rgba(0, 0, 0, 0.4)', // lighter: 'rgba(0, 0, 0, 0.25)', // lightest: 'rgba(0, 0, 0, 0.1)', // }, // }, colors: { 'smoke-darkest': 'rgba(0, 0, 0, 0.9)', 'smoke-darker': 'rgba(0, 0, 0, 0.75)', 'smoke-dark': 'rgba(0, 0, 0, 0.6)', 'smoke': 'rgba(0, 0, 0, 0.5)', 'smoke-light': 'rgba(0, 0, 0, 0.4)', 'smoke-lighter': 'rgba(0, 0, 0, 0.25)', 'smoke-lightest': 'rgba(0, 0, 0, 0.1)', }, }, variants: { opacity: ['responsive', 'hover', 'focus', 'disabled'], }, plugins: [require('#tailwindcss/ui')], }; After I "run npm dev" there are no other colors except those which I tried to add. How can I add those colors without deleting others? Commented section is just a try of different syntax, they both work the same.
You need to put your colors within the extend object: module.exports = { theme: { extend: { colors: { 'smoke-darkest': 'rgba(0, 0, 0, 0.9)', 'smoke-darker': 'rgba(0, 0, 0, 0.75)', 'smoke-dark': 'rgba(0, 0, 0, 0.6)', 'smoke': 'rgba(0, 0, 0, 0.5)', 'smoke-light': 'rgba(0, 0, 0, 0.4)', 'smoke-lighter': 'rgba(0, 0, 0, 0.25)', 'smoke-lightest': 'rgba(0, 0, 0, 0.1)', } } } } See the docs: https://tailwindcss.com/docs/customizing-colors#extending-the-defaults
Nodejs Xml to Json
I am using fast-xml-parser for coverting xml to json var parser = require('fast-xml-parser'); var he = require('he'); var fs = require("fs"); var util = require("util"); var options = { attributeNamePrefix : "#", attrNodeName: "attr", textNodeName : "#text", ignoreAttributes : true, ignoreNameSpace : true, allowBooleanAttributes : false, parseNodeValue : true, parseAttributeValue : false, trimValues: true, cdataTagName: "__cdata", //default is 'false' cdataPositionChar: "\\c", parseTrueNumberOnly: false, arrayMode: false, //"strict" attrValueProcessor: (val, attrName) => he.decode(val, {isAttributeValue: true}), tagValueProcessor : (val, tagName) => he.decode(val), stopNodes: ["parse-me-as-string"] }; var tObj = parser.getTraversalObj(xml,options); var jsonObj = (parser.convertToJson(tObj,options)); var lastJson = util.inspect(jsonObj, false, null, true); console.log(lastJson); My Output this but I dont want see root and elements how can I fix? { root: { BIREYSEL: { bkBildirimdeBulunanFinansKurulusuSayisi: 2, bkEnEskTakibeAlinmaTarihi: '', bkExclusionCode: '', bkGecikmedekiToplamHesapSayisi: 0, bkGeciktirdigiBakiyeToplami: 0, bkHesapDokumuBeans: { bkHesap: { element: [ { bkAcilisTarihi: 20190716, bkDovizKodu: 'TL', bkEnSonGuncellemeTarihi: 20190915, bkGecikmedekiBakiye: 0, bkHesaptakiKonumu: 1, bkKapanisTarihi: { element: '' }, bkKayitReferansNo: '7027461580078B', bkKrediKartiTaksitliBakiye: 263, bkKrediTuru: 23, bkKrediTutariLimiti: 12250, bkKurumRumuzu: 'A', bkLimitKullanimOrani: 0.09, bkOdemePerformansiTarihcesi: 0, bkSiraNo: 1, bkTakibeAlinmaBakiyesi: 0, bkTakipTarihi: '', bkToplamBakiye: 1026, bkToplamGeciktirilmisOdemeSayisi: 0, bkTuketiciKredisiTaksitSayisi: '', bkTuketiciKredisiTaksitTutari: '' }, { bkAcilisTarihi: 20110914, bkDovizKodu: 'TL', bkEnSonGuncellemeTarihi: 20190913, bkGecikmedekiBakiye: 0, bkHesaptakiKonumu: 1, bkKapanisTarihi: { element: '' }, bkKayitReferansNo: '5670737591250I', bkKrediKartiTaksitliBakiye: 0, bkKrediTuru: 23, bkKrediTutariLimiti: 3500, bkKurumRumuzu: 'B', bkLimitKullanimOrani: 0, bkOdemePerformansiTarihcesi: 0, bkSiraNo: 2, bkTakibeAlinmaBakiyesi: 0, bkTakipTarihi: '', bkToplamBakiye: 0, bkToplamGeciktirilmisOdemeSayisi: { element: '' }, bkTuketiciKredisiTaksitSayisi: '', bkTuketiciKredisiTaksitTutari: '' } ] } }, bkKrediNotu: 1369, bkKrediNotuSebepKodu1: 12, bkKrediNotuSebepKodu2: 6, bkKrediNotuSebepKodu3: 9, bkKrediNotuSebepKodu4: 17, bkMevcutEnUzunGecikmeSuresi: 0, bkSonKrediKullandirimTarihi: 20190716, bkSorguNo: 72626513, bkTakibiDevamEdenKrediSayisi: 0, bkTakipBildirimdeBulunanFinansKurulusuSayisi: 0, bkToplamKrediliHesapSayisi: 2, bkToplamLimit: 15750, bkToplamRisk: 1026, bkToplamTakibeAlinmisKrediSayisi: 0, bkToplamTakipBakiyesi: 0, bkWorstPaymetStatusEver: 0, krsSonucu: 0, krsVeriBulunduMu: true }, TICARI: { krmSonucu: 1, krmVeriBulunduMu: false, tkBildirimdeBulunanFinansKurulusuSayisi: 0, tkEnEskiTakipTarihi: '', tkEnGuncelLimitTahsisTarihi: '', tkEnYakinTakipTarihi: '', tkGecikmedekiHesapSayisi: 0, tkGecikmisBakiyeToplami: 0, tkGuncelKrediBakiyesiToplami: 0, tkIlkKrediKullandirimTarihi: '', tkLimitRiskBeans: '', tkSonKrediKullandirimTarihi: '', tkTakFaktoringBildirimDonemi: '', tkTakFaktoringCalistigiBankVeDigerMaliKurulusSayisi: 0, tkTakFaktoringFaizReeskontKomisyon: 0, tkTakFaktoringFaizTahakkukuKomisyon: 0, tkTakFaktoringKrediLimiti: 0, tkTakFaktoring_12_24_Ay_Vadeli: 0, tkTakFaktoring_1_12_Ay_Vadeli: 0, tkTakFaktoring_24_Ay_Vadeli: 0, tkTakLeasingBildirimDonemi: '', tkTakLeasingCalistigiBankVeDigerMaliKurulusSayisi: 0, tkTakLeasingFaizReeskontKomisyon: 0, tkTakLeasingFaizTahakkukuKomisyon: 0, tkTakLeasingKrediLimiti: 0, tkTakLeasing_12_24_Ay_Vadeli: 0, tkTakLeasing_1_12_Ay_Vadeli: 0, tkTakLeasing_24_Ay_Vadeli: 0, tkTakibeAlindigiTarihtekiRiskTutarlariToplami: 0, tkTakipHesabiBildirimdeBulunanFinansKurulusuSayisi: 0, tkTokFaktoringBildirimDonemi: '', tkTokFaktoringCalistigiBankVeDigerMaliKurulusSayisi: 0, tkTokFaktoringFaizReeskontKomisyon: 0, tkTokFaktoringFaizTahakkukuKomisyon: 0, tkTokFaktoringKrediLimiti: 0, tkTokFaktoring_12_24_Ay_Vadeli: 0, tkTokFaktoring_1_12_Ay_Vadeli: 0, tkTokFaktoring_24_Ay_Vadeli: 0, tkTokLeasingBildirimDonemi: '', tkTokLeasingCalistigiBankVeDigerMaliKurulusSayisi: 0, tkTokLeasingFaizReeskontKomisyon: 0, tkTokLeasingFaizTahakkukuKomisyon: 0, tkTokLeasingKrediLimiti: 0, tkTokLeasing_12_24_Ay_Vadeli: 0, tkTokLeasing_1_12_Ay_Vadeli: 0, tkTokLeasing_24_Ay_Vadeli: 0, tkToplamDigerLimit: '', tkToplamDigerRisk: 0, tkToplamGayriNakdiLimit: 0, tkToplamGayriNakdiRisk: 0, tkToplamLimit: 0, tkToplamNakdiLimit: 0, tkToplamNakdiRisk: 0, tkToplamRisk: 0 }, donusDegerleri: { hataKodu: 0, islemSonucu: 0 }, ersRaporTuru: 'D', raporTur: 'FD', referansNo: '603A796EB0', varlikTuru: 'G' } }
Data being modified during axios.get request
I am currently on a React project and the data being sent from the backend is being modified as it arrives on the frontend. I'm probably missing something really stupid but I cannot figure out where it's going bad for god's sake. The frontend component import React from 'react'; //.. import bunch of other things const styles = theme => ({ root: {}, sectionTitle: { margin: '20px 0 35px 0' }, sectionTitleNoTop: { margin: '0 0 35px 0' }, gap50: { margin: 50 } }); class RankingsPage extends React.Component { state = { tableData: null, tableDataEarnings: null, barData: null, barDataEarnings: null, tableError: '' }; constructor(props) { super(props); this.getBarData = this.getBarData.bind(this); } componentWillMount() { this.getBarData(false); //first request this.getBarData(true); //second request } async getBarData(earnings) { let response = await axios.get(`/api/ranking/ranking_barchart?earnings=${earnings}`); let {success, data, error} = response.data; console.log(earnings); console.log(data); //The first request works fine. retrieves following //[ { fill: true, // backgroundColor: 'rgba(58, 79, 212, 0.4)', // data: [ 11, 8, 8, 5, 5, 4, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] }, // { fill: true, // backgroundColor: 'rgba(239, 49, 81, 0.4)', // data: [ 0, 0, 0, 0, 10, 0, 15, 6, 10, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0 ] } ] //Second request gives this //[ { fill: true, // backgroundColor: 'rgba(58, 79, 212, 0.4)', // data: [ 11, 8, 8, 5, 5, 4, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] }, // { fill: true, // backgroundColor: 'rgba(239, 49, 81, 0.4)', // data: [ 11, 8, 8, 5, 5, 4, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] } ] //Notice that this part is different from the first if (!success) { return this.setState({barDataError: error}); } if (!earnings) { return this.setState({barData: data}); } this.setState({barDataEarnings: data}); } render() { const {classes} = this.props; const {tableData, tableDataEarnings, barData, barDataEarnings} = this.state; return ( <div className={classes.root}> //I'm using this.state.barData and this.state.barDataEarnings here - I don't think this code has anything to do with the problem but if you need it I'll provide </div> ); } } export default withStyles(styles)(RankingsPage) The component makes EXACTLY the same request except that the query value is different in the url. However, the data of the second index object is different to that of the first response. Now the more interesting thing is the backend. app.get('/api/ranking/ranking_barchart', authorize, async (req, res) => { try{ let earnings = req.query.earnings === 'true'; // let sortBy = earnings ? {totalReceived: -1} : {totalDonated: -1}; let sortBy = {totalReceived: -1}; let topUsersResult = await User.find({}) .sort(sortBy) .limit(20) .lean() .exec(); let returnBody = { labels: [], datasets: [] }; let donationsMade = { fill: true, backgroundColor:'rgba(239, 49, 81, 0.4)', data: [] }; let donationsReceived = { fill: true, backgroundColor:'rgba(58, 79, 212, 0.4)', data: [] }; for(let i = 0; i< topUsersResult.length; i++) { let curResult = topUsersResult[i]; returnBody.labels.push(curResult.username); donationsMade.data.push( curResult.totalDonated ? curResult.totalDonated : 0 ); donationsReceived.data.push( curResult.totalReceived ? curResult.totalReceived : 0 ); } returnBody.datasets.push(donationsReceived); returnBody.datasets.push(donationsMade); console.log(returnBody.datasets); //Print here is EXACTLY the same for both requests as expected res.json(API_MSG.successMsg(returnBody)); }catch(e){ res.json(API_MSG.errorMsg(e, MSG_TYPES.FIND_ERROR, true)); } }); I have it to NOT use the earnings query to test out with the EXACT same response. The code above is almost unnecessary because the console.log value is exactly the same as shown below. The console.log commented on the code above prints the following //First Request [ { fill: true, backgroundColor: 'rgba(58, 79, 212, 0.4)', data: [ 11, 8, 8, 5, 5, 4, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] }, { fill: true, backgroundColor: 'rgba(239, 49, 81, 0.4)', data: [ 0, 0, 0, 0, 10, 0, 15, 6, 10, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0 ] } ] //Second Request [ { fill: true, backgroundColor: 'rgba(58, 79, 212, 0.4)', data: [ 11, 8, 8, 5, 5, 4, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] }, { fill: true, backgroundColor: 'rgba(239, 49, 81, 0.4)', data: [ 0, 0, 0, 0, 10, 0, 15, 6, 10, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0 ] } ] PLEASE tell me I'm not crazy. How is the EXACT same response that is being returned from the server some how being modified while it's being transported to the frontend???
inserts not working mongodb
I'm having a problem while using a webtask as a backend web service to a static website. I'm using the web service to insert values to a mongodb database. The inserts are not returning any errors, but there is nothing inserting into the database. It just says 'worked' on the response. Here's the relevant code: var MongoClient = require('mongodb').MongoClient; function savePage (page, db, cb){ var doc = { pageSec: page }; db.collection("page").insertOne(doc, function (err) { if(err) {return cb(err);} cb('worked'); }); } module.exports = function(context, cb){ var section = context.query.section; if(section){ MongoClient.connect(context.data.mongoUri, function(err, db) { if(err) {return cb(err);} savePage(section, db, function (err) { if(err){return cb(err);} cb(null); }); }); } }; additionally, this is what mongodb returns in response to the insert "details": { "ok": 1, "n": 1, "lastOp": "6307485423539060737", "electionId": "576dec4e2c52240b7a5bca5e" }, "message": { "parsed": true, "index": 96, "raw": { "type": "Buffer", "data": [ 96, 0, 0, 0, 163, 69, 36, 3, 5, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 60, 0, 0, 0, 16, 111, 107, 0, 1, 0, 0, 0, 16, 110, 0, 1, 0, 0, 0, 17, 108, 97, 115, 116, 79, 112, 0, 1, 0, 0, 0, 147, 176, 136, 87, 7, 101, 108, 101, 99, 116, 105, 111, 110, 73, 100, 0, 87, 109, 236, 78, 44, 82, 36, 11, 122, 91, 202, 94, 0 ] }, "data": { "type": "Buffer", "data": [ 96, 0, 0, 0, 163, 69, 36, 3, 5, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 60, 0, 0, 0, 16, 111, 107, 0, 1, 0, 0, 0, 16, 110, 0, 1, 0, 0, 0, 17, 108, 97, 115, 116, 79, 112, 0, 1, 0, 0, 0, 147, 176, 136, 87, 7, 101, 108, 101, 99, 116, 105, 111, 110, 73, 100, 0, 87, 109, 236, 78, 44, 82, 36, 11, 122, 91, 202, 94, 0 ] }, "bson": {}, "opts": { "promoteLongs": true }, "length": 96, "requestId": 52708771, "responseTo": 5, "responseFlags": 8, "cursorId": "0", "startingFrom": 0, "numberReturned": 1, "documents": [ { "ok": 1, "n": 1, "lastOp": "6307485423539060737", "electionId": "576dec4e2c52240b7a5bca5e" } ], "cursorNotFound": false, "queryFailure": false, "shardConfigStale": false, "awaitCapable": true, "promoteLongs": true }
When I build my JSON object to sent to MongoDB, I always set the property name as string and it works. var doc = { "pageSec": page }; I don't see anything wrong in your code, so you can try this.